Skip to main content
September 13, 2010
Answered

CFfile multiple upload problem

  • September 13, 2010
  • 1 reply
  • 732 views

Hello~

I am using two cfinput tags with a type of "file" within the same form. They accept different file types, using regex validation to check each, and have different name and id values.

<!--- FORM FIELDS --->

<cfinput type="file" name="pageLayoutCSSFileUpload" class="inputArea" message="Please upload a .css file." required="yes" size="50" id="pageLayoutCSSFileUpload" validate="regex" pattern="^.*\.(css|CSS)$" />

<cfinput type="file" name="pageLayoutImageUpload" class="inputArea" message="Please upload a layout image (.gif)." required="yes" size="50" id="pageLayoutImageUpload" validate="regex" pattern="^.*\.(gif|GIF)$" />

Once the form is submitted, I am using cffile to upload each to the same directory, with the same name, but different extensions (one .css and one .gif). The first file, .css, uploads correctly. Then I get an error with the second cffile tag that the mime-type is incorrect, and that the file must be in the image/gif format. I know that the test files I am using are in the correct format, so it seems like the second cffile tag is looking at the first file that is being uploaded. I don't know how this can happen, as the "file" value for each cffile tag is being set through a form variable, which relates directly to the two seperate input fields.

<!--- FORM ACTION --->

<!--- upload page layout CSS file --->
<cffile action="upload" destination="#local.pageLayoutsPath#pageLayout_#numberFormat(local.layoutID,000)#" file="#form.pageLayoutCSSFileUpload#" nameconflict="error" result="local.pageLayoutCSSFileUpload" accept="text/css" />
               
<!--- upload page layout image file (large) --->
<cffile action="upload" destination="#local.pageLayoutsPath#pageLayout_#numberFormat(local.layoutID,000)#" file="#form.pageLayoutImageUpload#" nameconflict="error" result="local.pageLayoutImageUpload" accept="image/gif" />

Has anyone else had this problem? It is complicated to explain, so let me know if this doesn't make sense... Thanks!

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    According to the docs (and my past experience):

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-738f.html

    <cffile action="upload"> requires a FILEFIELD attribute, which should be the name of the form field relevant to the file in question.  Note: not the VALUE of the form field, but the NAME of it.

    I'm surprised your code isn't erroring, given FILEFIELD is - appaerently - required.

    --

    Adam

    1 reply

    Adam Cameron.Correct answer
    Inspiring
    September 13, 2010

    According to the docs (and my past experience):

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-738f.html

    <cffile action="upload"> requires a FILEFIELD attribute, which should be the name of the form field relevant to the file in question.  Note: not the VALUE of the form field, but the NAME of it.

    I'm surprised your code isn't erroring, given FILEFIELD is - appaerently - required.

    --

    Adam

    September 13, 2010

    Thanks so much, that was definitely it! My fault for not naming the attribute correctly, but a helpful error message would have been nice


    Inspiring
    September 13, 2010

    No worries.

    I reckon the bad error message is a bug.  Perhaps you'd (as you spotted it) like to raise it as such: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.htm

    If you report back with the bug ref, I'll vote for it too.

    --

    Adam