DEV Community

James Moberg
James Moberg

Posted on

Identifying Random Uploaded Form Files

I'm developing a flexible processing CFML script that accepts (authenticated) FORM posts and processes the data. The data is stored based on form field prefixes, but I don't have any hints regarding which fields may contain a file when processing a "multipart/form-data" form posts. I found Ryan Stille's blog post from 2012 entitled "Getting the client filename before using cffile", but it didn't work with Lucee.

I've been using Ryan's Adobe ColdFusion-only UDF for a couple years, but I need a cross-compatible solution since I'm attempting to migrate some projects to Lucee. I searched & couldn't find anything, so I thought I'd try my hand at it. (I'm not 100% sure if this is the best way to do it since it uses an undocumented method.)

The benefit to this approach is that it returns a single struct containing keys that match all form "file" field names with extra information identifying the original filename, type, size and temporary file path. Enjoy!

getFormFiles UDF (cross-compatible cfml)

Discussion (0)