Last active
August 29, 2015 14:08
-
-
Save rip747/533611f75bf2156be622 to your computer and use it in GitHub Desktop.
CFML Rack Middleware idea for returning a list of uploaded files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
// credit to David "MisterDai" Boyer | |
// http://misterdai.yougeezer.co.uk/posts/2012/03/08/coldfusion-10-beta-multiple-html5-multiple-uploads-bug/ | |
if (cgi.request_method == 'POST') { | |
WriteDump(var = form, label = "Form Scope"); | |
for (field in form) { | |
form[field] = ListToArray(form[field]); | |
} | |
WriteDump(var = form, label = "Form Scope - Parsed"); | |
// Dump the temporary files created by the uploads | |
WriteDump(var = form.gettempfiles(), label = "Form.getTempFiles()"); | |
// Dump the "parts" of the upload request CF found. | |
WriteDump(var = form.getPartsArray(), label = "Form.getPartsArray()"); | |
// Parse form.getPartsArray() to show what uploads were processed. | |
uploads = {}; | |
ArrayEach(form.getPartsArray(), function(el) { | |
fieldName = el.getName(); | |
if (Not StructKeyExists(uploads, fieldName)) { | |
uploads[fieldName] = el.getFileName(); | |
} else if (Not IsArray(uploads[fieldName])) { | |
uploads[fieldName] = [uploads[fieldName], el.getFileName()]; | |
} else { | |
ArrayAppend(uploads[fieldName], el.getFileName()); | |
} | |
}); | |
WriteDump(uploads); | |
} | |
</cfscript> | |
<cfif cgi.request_method eq 'POST'> | |
<cffile action="uploadAll" destination="#getTempDirectory()#" result="q" nameConflict="overwrite" /> | |
<cfdump var="#q#" label="uploadall"> | |
</cfif> | |
<form method="post" enctype="multipart/form-data"> | |
<label>First: | |
<input type="file" name="first" multiple="multiple" /> | |
</label><br /> | |
<label>Second: | |
<input type="file" name="second" multiple="multiple" /> | |
</label><br /> | |
<label>Third: | |
<input type="file" name="third" multiple="multiple" /> | |
</label><br /> | |
<label>Forth: | |
<input type="file" name="forth" /> | |
</label><br /> | |
<input type="submit" value="Upload" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment