Geo
Geo

Reputation: 3200

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

Upvotes: 1

Views: 2417

Answers (2)

Josh
Josh

Reputation: 992

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.)

Upvotes: 1

Miguel-F
Miguel-F

Reputation: 13548

Does the directory structure that you are referencing in the destination attribute exist '"#expandpath('../../images/Uploads/after')#"'?

If the destination attribute is not an absolute path then it is relative to ColdFusion's temp directory. Not relative to your web root or the template that is running.

Here is the description from the docs here

Pathname of directory in which to upload the file. If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function.

Upvotes: 0

Related Questions