Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / October 2005



Tip: Looking for answers? Try searching our database.

make cffile optional?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cobramichelle - 28 Oct 2005 16:51 GMT
I have created a page where people can upload screen shots of error messages..
now how can I make the field optional (i.e. Saving empty (zero-length) files)
as it's not mandatory?

code is below:

<cfif IsDefined("form.file")>

 <cfset thisPath = ExpandPath("*.*")>
<cfset thisDirectory = GetDirectoryFromPath(thisPath)>
<cffile action="UPLOAD" filefield="file" destination="#thisDirectory#"
nameconflict="OVERWRITE">
<cfelseif cffile.fileWasSaved IS "Yes">
<h1>File successfully uploaded</h1>
<cfelseif cffile.fileWasSaved IS "No">
<h1>Error uploading file</h1>
</cfif>
mxstu - 28 Oct 2005 19:38 GMT
Unless you have a reason for saving a zero length file, I would check the
length of the form field and if it it is empty, skip the upload.  

Also, "FILE" is a reserved word. You might consider changing the form field
name to something else (eg.  form.uploadFileName).  This will help avoid
potential problems or conflicts when referring to that variable without a scope.

<cffile action="UPLOAD" filefield="file" destination="#thisDirectory#" ...>
cobramichelle - 28 Oct 2005 20:29 GMT
Thanks a bunch mxstu

question:
I am saying if less than one.. to just display a message saying "thank you"
after the following line
<cfif LEN("form.uploadFileName") LT 1>
say "thank you"

then

<cfelseif LEN("form.uploadFileName") GT 1>
..upload the file..

** uploading works fine.. when I have no document to upload I still get the
"no zero length" -
mxstu - 28 Oct 2005 21:05 GMT
> <cfif LEN("form.uploadFileName") LT 1>

Remove the quotes around the form field name.  By using double quotes here
you're checking the length of the literal string "form.uploadFileName", not the
form field value. Try:

<cfif LEN(form.uploadFileName) EQ 0>
Thanks
<cfelse>
... upload the file
</cfif>
cobramichelle - 28 Oct 2005 21:30 GMT
That worked, thank you so much. I appreciate it ;-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.