[Looking for Charlie's main web site?]

If a file is uploaded and no CFFILE Upload tag exists to process it, does it really upload?

I was sharing some thoughts on a discussion list and figured others may appreciate the observation. Have you ever assumed that what CFFILE Action="upload" is what causes a file to be uploaded to your server? It doesn't. What it really does is move the uploaded file from a temp directory to your named DESTINATION (as well as validate its type, report the file name, protect against or allow overwrites, and more).

Need proof? Just do an form file upload to a CFM page that has no CFFILE Action="upload". The file will still be uploaded, to a temp directory (from which CFFILE *would* move it). There's a trick, though. The temp file (literally with a .tmp extension) will be removed when the upload page processing is done. You need to pause the page long enough to watch the directory to see it uploaded. Fortunately, in CFMX and BD, that's easily done.

Here's a template that demonstrates it all (see the comments/explanation that would appear onscreen):

<form method="post" enctype="multipart/form-data">
   <input type="File" name="test"><br>
   <input type="Submit"><br>
</form>
File will be uploaded to this directory: <br>
<textarea cols="100">
<cfoutput>#gettempdirectory()#</cfoutput>
</textarea><br>

The filename above was put in a text area to make it easy to copy/paste. Open that directory with windows exporer or its equivalent, and run the upload. Refresh the directory display to see the .tmp file. This page has been set to pause for 5 seconds after the upload. The tmp file will disappear when the form submission page process has completed.

<cfif request_method is "post">
   <cfscript>
    thread = createObject("java", "java.lang.Thread");
    thread.sleep(javaCast("long", 5000));
   </cfscript>
</cfif>
So what's actually doing the upload? I would assume the web server. Why is it going into a CF (or BD) temp directory? I assume it's because the web server adapter causes the web server to tell it to do so. It might be useful to try to do an upload to a plain HTM extension file, but you need a means to cause the page to pause to see if the file was uploaded (to an OS-specific temp directory, I'd guess). I tried uploading large files and just couldn't see them being uploaded to the temp directory without doing the pause.

Hope this helps someone.

Comments
Charlie,

I had learned from my first efforts with CFFile that it doesn't actually upload the file, it just transfers it from the server's temp directory to the specified directory, or to the application's memory. From what I understand, the file form field just gives a path to the uploaded file in the temp directory.

That said, even though CFFile may not be working as advertised, there are still ways you can upload the file and process the uploaded file using the java.io.String and FileReader classes. Samuel Neff gives a very nice discussion on how to do this on his blog:

http://www.rewindlif...

Of course this assumes that your shared hosting account allows you to use createObject and java in general.

See you at CFUnited.

larry
# Posted By Larry C. Lyons | 5/9/06 4:24 PM
Larry, thanks, but I wasn't asserting that it wasn't working. I was just explaining, for those who have thought CFFILE did the uploading, that it does not: that (as you say) all it does is the move on the server from temp to intended destination. I was just pointing this out for those who have wondered or want, in the future, a place to point those who would argue otherwise. See you at the conference.
# Posted By Charlie Arehart | 5/9/06 4:43 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.

Managed Hosting Services provided by
http://www.edgewebhosting.net/
Managed Dedicated Hosting