PDA

View Full Version : FileUploadField in Coldfusion problems



emoshag
24 Nov 2010, 10:00 AM
Hello,

I am designing a component in an application that will handle uploading files. I have read the documentation on the BasicForm fileUpload in the API documentation and I have looked at the examples.

Problem is two fold:
I am not a PHP developer. I am working in Coldfusion.
I also am restricted to Coldfusion 7 (before integrated JSON support)


In the EXTJS example the PHP file called has two lines of code:


<?php
sleep(1);
echo '{success:true, file:'.json_encode($_FILES['photo-path']['name']).'}';Now... all this appears to be doing is returning a success message and a JSON encoded string of the filename. But it actually isn't doing anything. Its not uploading the file.


<cfsetting showdebugoutput="yes">

<cfset Err = "">

<cftry>
<cfset destination = expandPath("../uploads_test")>
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>

<cffile
action="upload"
filefield="#photo-path#"
destination="#destination#"
nameConflict=""makeUnique"
result="upload">
<cfcatch type="any">
<cfset Err = "Still doesn't work.">
</cfcatch>
</cftry>

<cfif Err = "">
<cfset result = '{success:true, msg:"Worked."}'>
<cfelse>
<cfset result = '{success:false, msg:"#Err#"}'>
</cfif>

<CFCONTENT type="text/html" RESET="Yes">
<CFOUTPUT>#result#</CFOUTPUT>My CFM page that processes Coldfusion works perfectly for all other form submission and processing EXCEPT for this annoying file upload process. And the file upload process is copied out of the coldfusion page that I originally wrote which was a standard multipart form submission.

How exactly is this wrong? What am I doing that makes this form submission not work? I have basically copied the entire example and changed the file-upload.php to file-upload.cfm and used my already working CFM code and its broken.

Any help or suggestions would be greatly appreciated. I have been trying this for 3 days with no success....

wuschba
25 Nov 2010, 1:38 PM
Sorry, I don't know coldfusion, but in general you have to take care of the upload for yourself. In php you have to check variables like:
$sTmpFile = $_FILES['photo-path']['tmp_name'];
$sFilename = $_FILES['photo-path']['name'];
$nFileSize = $_FILES['photo-path']["size"];
and then use:
move_uploaded_file
to copy the file from the php-tmp-upload-folder to the destination you want.