Skip to main content
Known Participant
January 29, 2013
Question

upload files in form

  • January 29, 2013
  • 1 reply
  • 595 views

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.

    This topic has been closed for replies.

    1 reply

    WolfShade
    Legend
    January 29, 2013

    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

    ^_^

    Known Participant
    January 29, 2013

    yea... I just upload the file and check it and then delete it if there is a problem.or not the right file type.