Copy link to clipboard
Copied
Hey I have a form that uploads a file. I am having trouble with some of the code and hoping someone can help.
FORM FIELD
<tr>
<td><strong>Upload Submission</strong></td>
<td><input
type="file"
name="submission"
id="submission"
value="#FORM.submission#" class="submissionclass"
/></td>
</tr>
on submission of the form this code runs
PROCESSING CODE:
<cfif FORM.submission EQ " ">
<cfset errors = Errors & "<li>Only PDF, DOC, and DOCX file formats are accepted</li>">
</cfif>
<cfif FORM.submission NEQ " ">
<cfif #right(#FORM.submission#, 4)# NEQ "docx" OR #right(#FORM.submission#, 3)# NEQ "doc" OR #right(#FORM.submission#, 3)# NEQ "pdf">
<cfset errors = Errors & "<li>Only PDF, DOC, and DOCX file formats are accepted</li>">
</cfif>
</cfif>
The questions is will this work or do I have to do it another way.
Copy link to clipboard
Copied
Why bother with the conditional if both cases result in errors being set to the warning of "only certain file formats are accepted"?
Also, <cfif #right(#form.submission#,4)# is slowing you down. The #'s are used inside strings or CFOUTPUTs. The line S/B <cfif right(form.submission,4)
Actually, instead of using right(), use listGetAt(form.submission,len(form.submission),"."), this will split the filename into a period-delimited list, getting the last list element (the file extension) for comparison.
Just my $0.02
^_^
Copy link to clipboard
Copied
yea... I just upload the file and check it and then delete it if there is a problem.or not the right file type.
Copy link to clipboard
Copied
WolfShade wrote:
Actually, instead of using right(), use listGetAt(form.submission,len(form.submission),"."), this will split the filename into a period-delimited list, getting the last list element (the file extension) for comparison.
Correction: listGetAt(form.submission,len(form.submission),".") should be listGetAt(form.submission,LISTLEN(form.submission),".")
^_^