Skip to main content
Participant
June 27, 2007
Question

Upload File: Make File Field NOT required

  • June 27, 2007
  • 2 replies
  • 468 views
I have a form that submits product information to Access db and uploads image.. That part works great. However if i do not have an Image to upload for a product the form spits out error.

The form field "ItemImage" did not contain a file.

I want to be able assign ItemImage value as "default.gif" in the db if no file was uploaded.

Here is a look at my source. Can someone please help me with this.

The form field "ItemImage" did not contain a file.

<cfif isdefined("form.upload_now")>
<div align="center" class="style5">
<cffile action="upload" filefield="ItemImage" destination="c:\ohlWestIms\scripts\purchase-orders\images\" accept="image/jpeg, image/x-png, image/pjpeg, image/gif" nameconflict="Skip">
Item has been Added .



<cfquery datasource="dsnPurchaseOrders">
INSERT INTO Items (ItemName, ItemDiscrip, ItemPrice, ItemImage, ItemCompany, ItemNumber)
VALUES (
<cfif IsDefined("FORM.ItemName") AND #FORM.ItemName# NEQ "">
'#FORM.ItemName#'
<cfelse>
NULL
</cfif>
,

<cfif IsDefined("FORM.ItemDiscrip") AND #FORM.ItemDiscrip# NEQ "">
'#FORM.ItemDiscrip#'

<cfelse>
NULL
</cfif>

,

<cfif IsDefined("FORM.ItemPrice") AND #FORM.ItemPrice# NEQ "">
'#FORM.ItemPrice#'

<cfelse>
NULL
</cfif>

,

<cfif IsDefined("FORM.ItemImage") AND #FORM.ItemImage# NEQ "">
'#cffile.ServerFile#'

<cfelse>
NULL
</cfif>

,

<cfif IsDefined("FORM.ItemCompany") AND #FORM.ItemCompany# NEQ "">
'#FORM.ItemCompany#'

<cfelse>
NULL
</cfif>

,

<cfif IsDefined("FORM.ItemNumber") AND #FORM.ItemNumber# NEQ "">
'#FORM.ItemNumber#'

<cfelse>
NULL
</cfif>



)
</cfquery>


</div>
</cfif>


This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
June 29, 2007
Have you tested your code using if-statements I gave? They should answer your question.

BKBK
Community Expert
Community Expert
June 27, 2007
You could impose

<cfif isdefined("form.upload_now") and len(trim(form.upload_now)) GT 0>

to ensure that the upload will only continue if the client entered something in the upload_now field. You could impose

<cfif isdefined("form.upload_now") and len(trim(form.upload_now)) GT 0 and CGI.CONTENT_LENGTH GT 500>

to ensure that the upload will only continue if the client indeed uploaded a file. We assume here that a small amount of upload, at least 500 bytes, is an indication that a file has been uploaded.


Participant
June 28, 2007
Not sure I explained this right. Sometimes there will be times when we dont have an image to upload for products. So I want to be able to skip that field and not produce the Error. Right now if I skip it, i get the message "The form field "ItemImage" did not contain a file."