Search code examples
coldfusioncoldfusion-9

CFFILE Upload all Issues - Coldfusion 9


I am trying to use this code for uploading files to my server but is giving me an error.

This is the code:

 <cfif isdefined("form.submit")> 
   <cffile action="uploadall" destination="#expandpath('../../images/Uploads/after')#"> 
 </cfif> 
 <cfform action="#cgi.script_name#" enctype="multipart/form-data"> 
   <cfinput type="file" name="attachment1"><br> 
   <cfinput type="file" name="attachment2"><br> 
   <cfinput type="file" name="attachment3"><br> 
   <cfinput type="submit" name=" submit" value="submit"> 
 </cfform>

This is the Error:

The following information is meant for the website developer for debugging purposes.

Error Occurred While Processing Request

Invalid content type: application/x-www-form-urlencoded.

The files upload action requires forms to use enctype="multipart/form-data".

The error occurred in E:\sites\Example.Com\testing\handlers\upload\after.cfm: line 20


Solution

  • I see that you've moved on to a different solution, but I wanted to answer your question because the answer is plain crazy (and is stereotypical of some of the bizarre gotchas in Coldfusion). The problem is that <cfform> simply doesn't support the enctype attribute. If you want to upload files, you have to use a plain <form>. Weird, right?

    (I suppose you could change the XSLT so that a cfform with a file input results in the enctype being set correctly automatically. But why it doesn't do this out of the box is beyond me.)