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>
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 ;-)