Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

upload files in form

Community Beginner ,
Jan 29, 2013 Jan 29, 2013

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.

547
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2013 Jan 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

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 29, 2013 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2013 Jan 29, 2013
LATEST

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

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources