I am trying to implement an HTML5 input field that lets the user select multiple files to upload. I have the following in my form:

<form method="post" enctype="multipart/form-data" action="index.cfm">
    <input type="file" name="Images" id="Images" multiple="multiple" accept="image/jpeg, image/gif, image/png, application/zip" />
    ...

I am able to select multiple files in the browser, then click upload, but I'm not sure how to handle the form post with ColdFusion. I thought the following would work, but this only uploads the last file I selected:

<cfloop list="#attributes.Images#" index="Image">
    <cffile 
        destination = "#ExpandPath(Trim(request.TempFolder))#" 
        filefield = "Images" 
        action = "upload" 
        nameconflict = "MakeUnique" 
        result = "UploadedTempFile"
    >
    <cfoutput>#UploadedTempFile.serverFile#<br /></cfoutput>
</cfloop>

Can someone explain to me how to loop through all the files submitted through my one form field so I can handle the files individually? Thanks!

link|improve this question

62% accept rate
1  
Have you tried using <cffile action="uploadAll" />? It's CF9 only, and I haven't tested it myself, but that may do the trick. In CF8, I'm just getting the one Images field. – Dan Short Sep 7 '11 at 18:21
Damn, that's exactly what I need, but I'm stuck with CF8 at the moment. Any suggestions? – Michael Sep 7 '11 at 18:48
Not with an HTML 5 form :/, I use Uploadify for these types of uploaders in CF8, or the cffileupload tag in CF9. I'm honestly not sure if the solution I provided would even work... – Dan Short Sep 7 '11 at 18:50
After a second look, it seems like uploadAll was created to handle multiple input elements of the same name. I'm really just trying to handle one input element with attribute "multiple". I was hoping it would just create an array of files and I could loop through those individually, kind of how you would loop through multiple text input fields of the same name. – Michael Sep 7 '11 at 19:53
I'll have to test it out, because when I used your sample form in CF8 it showed multiple form elements named "images", not a single form element. I'll see if I can make the uploadall work in CF9 and get back to you. – Dan Short Sep 7 '11 at 19:56
show 2 more comments
feedback

1 Answer

up vote 1 down vote accepted

UPDATE: As of ColdFusion 9 this was true. This has been corrected in ColdFusion 10.

So to wrap up our comment conversation:

This simply isn't possible with default ColdFusion behavior. cffile doesn't support handling multiple file uploads from a single file element. I think it could potentially be possible to fallback to JAVA to do this, but I wouldn't have a clue how to make that happen.

I would love cffile action="uploadall" to grab all HTML5 multi-file elements. Will need to file that as an ER for CF10 :).

link|improve this answer
Yes, it is supported in CF10's cffile action=uploadall – Henry May 17 at 20:06
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.