Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

overiding a blank upload field

Status
Not open for further replies.

ma701sd

IS-IT--Management
Dec 15, 2000
94
GB
Hi,

Is there anyway to bypass a blank file upload field from a form i.e. if a user does not specify a a file to upload then the corresponding action page just bypases it.

Ive tried puttingan if statement around the upload section on the action page but no joy.
Heres the snippet:
<CFIF #Form.ImageSection1# IS &quot;&quot;>
No Image submitted
<CFELSE>

<CFFILE ACTION=&quot;Upload&quot;
FILEFIELD=&quot;ImageSection1&quot;
DESTINATION=&quot;c:\webshare\NAMECONFLICT=&quot;Overwrite&quot;>

<IMG SRC= &quot;../Project1/Users/#Client.UserName#/#cffile.serverFile#&quot;>

</cfif>
</cfoutput>

Thanks for the help in advance

Sam
 
I believe you want <CFIF not isdefined(&quot;Form.ImageSection1&quot;)>. It's been a while since I coded with file inputs but I think that's what works. If not, let me know and I'll dig up some old code.

GJ
 
Hey GJ,
Hope you are well :)

I tried the what you suggested but no joy..

Im still getting the error:
&quot;Error processing CFFILE

No data was received in the uploaded file '\.' Saving empty (zero-length) files is prohibitted. Please make sure you specified the correct file. &quot;

Any other ideas??

Cheers
Sam
 
First of all, make sure you have the enctype specified in yoyr <FORM> tag, this often causes problems you refer to. It should be like this:

<form action=&quot;ActionPage.cfm&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>

Then, in your action page, check if something is selected:

<cfif Len(FORM.ImageSection1) GT 0>
<!--- CFFILE code here --->
<cfelse>
Please select a file to be uploaded!
</cfif>

Hope this helps...
<webguru>iqof188</webguru>
 
Well,

I am passing a formfield from an input page and I am checking to see if the user inputted a location for a file:

<CFIF FileExists (Form.Section1Image1)>
&quot;Upload sysntax&quot;
<CFELSE>
No Image submitted

It executes the <CFELSE> clause but it also parses the statement within <CFIF>.
What I basically want to do is to bypass the upload if the user does not specifiy a file to upload (Therefore the user has a choice to upload a file or not) So if the field is blank then no file to upload else if there is a location within the field then upload the file.
Im not sure if there is a way to bypass i.e. if CFFILE ACTION=&quot;UPLOAD&quot; Then CF Has to have a file to upload??

If anyone can help

Cheers
Sam
 
Hey Sam,

I was wrong on my earlier post, the field will exist but will be blank so your original code was correct. I just tested this and it works correctly. Is this what you're needing?

<cfif SectionImage1 is &quot;&quot;>

Image Not Uploaded. All relevant code here.

<cfelse>

<CFFILE ACTION=&quot;Upload&quot;
FILEFIELD=&quot;SectionImage1&quot;
DESTINATION=&quot;d:\temp&quot;
NAMECONFLICT=&quot;Overwrite&quot;>

All other upload code here.

</cfif>

It correctly executes one section or the other depending on whether a file was uploaded. Let me know if you still have problems or if I'm missing the problem.

Good luck,
GJ
 
Hey GJ,

Thanx, It works like a treat... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top