Reputation: 299
I'm using Coldfusion 8 on an Ubuntu Linux server with Apache and MySQL. Any file uploaded get stored in the Coldfusion temp directory: [/opt/coldfusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp17260.tmp] I obviously want it to be stored in to /var/www/cfm3/images [which the value of #destination#. I have tried other solutions provided by this site but they tend to fork off to other solutions that have not solved my solution. Below is the an example of my code.
<cfset destination = expandPath("images") />
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cfloop from="1" to="#num_users#" index="i">
<cfoutput>User #i# Photo Upload :
<cfif isDefined("#i#")>
<cffile action="upload"
fileField="#i#"
accept="image/jpeg, image/gif, image/png"
destination="#destination#"
nameConflict="makeUnique"
mode = 777>
<cfdump var="#upload#">
<p>Thank you, your file has been uploaded.</p>
</cfif>
<input type="file" name="#i#" /><br />
</cfoutput>
</cfloop>
Any help would be greatly appreciated. :D
Upvotes: 0
Views: 3009
Reputation: 3762
I have a hunch the problem lies within how you are creating the destination
variable, assuming it is correct (even after a create), and then immediately passing it to CFFILE.
Refer to this similar question (and solution):
Saving File to Server in ColdFusion
In this question linked above, the answerer notes that:
The destination has to be a full path, otherwise it gets sent to a directory relative to the temp directory of Cold Fusion [sic].
This is very similar behavior to what you are experiencing--you want the file in a specific folder, but rather than error out, it ultimately lands in the "temp" dir.
I'd get some trace/debugging info in your template, specifically surrounding the value of the destination variable, prior to it being fed to CFFILE. Something doesn't quite gel with your description, and it could very well be a faulty path, or perhaps permissions surrounding it.
Upvotes: 3
Reputation: 16955
Are you getting an error similar to "upload not defined"? If so, change this line:
<cfdump var="#upload#">
To this:
<cfdump var="#cffile#">
If you aren't getting that error.... what output are you getting?
edit
Also, personally I wouldn't name your form fields as simple numbers. Try changing to this:
<cfloop from="1" to="#num_users#" index="i">
<cfoutput>User #i# Photo Upload :
<cfif isDefined("user#i#")>
<cffile action="upload"
fileField="user#i#"
accept="image/jpeg, image/gif, image/png"
destination="#destination#"
nameConflict="makeUnique"
mode = 777>
<cfdump var="#cffile#">
<p>Thank you, your file has been uploaded.</p>
</cfif>
<input type="file" name="user#i#" /><br />
</cfoutput>
</cfloop>
Note the "user" prefix before your field names.
Upvotes: 0