3 Replies Latest reply on Jan 29, 2013 12:41 PM by WolfShade

    upload files in form

    TheScarecrow Level 1

      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.

        • 1. Re: upload files in form
          WolfShade Level 4

          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

           

          ^_^

          • 2. Re: upload files in form
            TheScarecrow Level 1

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

            • 3. Re: upload files in form
              WolfShade Level 4

              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),".")

               

              ^_^