Copy link to clipboard
Copied
I am doing a cffile uploadall process and I want to return a list/array of filenames uploaded. It doesn't seem like it should be too hard - should it?
Thanks.
Copy link to clipboard
Copied
Take a look at the CF documentation. It states: After a file upload is completed, this tag creates an array of structures specified by the result parameter. Each structure in the array contains upload result information for one file. For information on the result structure contents, see cffile action = "upload".
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7388.html
Copy link to clipboard
Copied
Here's my code:
Upload page -
<cffileupload
hideuploadbutton="no"
progressbar= "no"
stoponerror="yes"
title="Upload Closeout Pictures"
url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(form.type)#"
wmode="transparent"
maxfileselect=6 />
<cfif isDefined("myImage.serverfile")>
wow
<cfelse>
hey
</cfif>
Processing page -
<cffile
action="uploadall"
destination="#path#"
nameconflict="overwrite"
result="myImage" />
I get nothing in the myImage variable.
Copy link to clipboard
Copied
Are any errors logged? It sounds like the file upload process is failing. You might try setting stoponerror="false" and use onError to gather information about the upload process from the cffileupload tag.
Copy link to clipboard
Copied
The upload is working fine - the files are going exactly where they should go. What I want to do is, after the upload, update a single record in a database with between 1 - 6 image names that were uploaded.
Copy link to clipboard
Copied
If the upload succeds you should have something your myImage variable. Try something like this in process.cfm to see what is captured in the result variable:
<cffile action="uploadall" destination="#path#" nameconflict="overwrite" result="myImage">
<cfif IsDefined("myImage")>
<cflog text="Upload complete" type="information">
<cfif IsArray(myImage)>
<cflog text="#ArrayLen(myImage)# files uploaded" type="information">
</cfif>
</cfif>
Copy link to clipboard
Copied
What do you mean when you write "I get nothing in the myImage variable." Is an exception thrown, is the array empty, etc?
Copy link to clipboard
Copied
I do the isDefined( ) in a cfif and it does not validate.
Copy link to clipboard
Copied
Not sure if I'm reading this right - but what page is the <cfif IsDefined("myImage")> declared? In the "Upload" page or the "Processing" page? If it's in the "Upload" page (the one containing <cffileupload - from the code you have supplied) then it will always evaluate to false as "myImage" was declared and teminated in the "process.cfm" page. You would need to do that check within the process.cfm page and update your database within that page too.
Copy link to clipboard
Copied
I certainly don't claim to know but when putting the logic in the processing page, I never got anywhere because of the flash object. I saw an example somewhere of someone that put the logic into the upload page so I tried it. I can get the processing page to return data to upload page - just not the variable I'm trying to evaluate.
Copy link to clipboard
Copied
Bear in mind that the Flash based file upload operates asynchronously rather than on a syncronous form post and response used with a form based file upload. I agree with the other poster that your database update logic should be handled on the process.cfm page.
If you must have the client handle data processing you can try the onError, onComplete, and onUploadComplete features of cffileupload, but I would recommend against having the client be responsible for this kind of logic.
Copy link to clipboard
Copied
I'm OK with that. Can anyone give me an example or point out what needs to be
changed in my code posted earlier?
Copy link to clipboard
Copied
On upload.cfm:
<cffileupload
hideuploadbutton="no"
progressbar= "no"
stoponerror="yes"
title="Upload Closeout Pictures"
url="process.cfm"
wmode="transparent"
maxfileselect=6>
On process.cfm
<cfset targetPath="X:\a-file-storage-directory">
<cffile action="uploadall" destination="#targetPath#" nameconflict="overwrite" result="uploadedFiles">
<!--- iterate over uploadedFiles result array and perform an insert for each record --->
<cfif IsDefined("uploadedFiles") and IsArray(uploadedFiles) and ArrayLen(uploadedFiles) gt 0>
<cfloop from="1" to="#ArrayLen(uploadedFiles)#" index="idx">
<cfquery name="insertFileRecord">
INSERT INTO FileHistory ( DirectoryName, FileName )
VALUES (
<cfqueryparam value="#uploadedFiles[idx].serverDirectory#" cfsqltype="cf_sql_varchar">
,<cfqueryparam value="#uploadedFiles[idx].serverFile#" cfsqltype="cf_sql_varchar">
);
</cfquery>
</cfloop>
</cfif>
Copy link to clipboard
Copied
I used your code and received a 500 status error in the flash object. I believe it is because I have to pass variables to the processing page for the query.
On the upload page:
<cffileupload
hideuploadbutton="no"
progressbar= "no"
stoponerror="yes"
title="Upload Closeout Pictures"
url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(type)#"
wmode="transparent"
maxfileselect=6 /
Copy link to clipboard
Copied
Did you check the ColdFusion log to see what errors, if any, were logged?
Copy link to clipboard
Copied
Yes, and I was able to fix the error. Now my problem is... it only updates with the last of the image names.
My table layout is
Pro_num, type, issue, pic1, pic2, pic3, pic4, pic5, pic6
Even though I uploaded 2 images, it updated pic1 with the second image name. I'm not sure if that makes sense.
Copy link to clipboard
Copied
Please post your code.
Copy link to clipboard
Copied
</cfif
Copy link to clipboard
Copied
Your code was truncated. Please also post both the upload.cfm and process.cfm pages.
Copy link to clipboard
Copied
Upload.cfm
</cfif
Copy link to clipboard
Copied
Your code continues to be truncated. If you are using email to reply please consider using the forum's web page instead. I have found that code is frequently mangled when posting to the forum by email.
Copy link to clipboard
Copied
Upload.cfm
<cffileupload
hideuploadbutton="no"
progressbar= "no"
stoponerror="yes"
title="Upload Closeout Pictures"
url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(type)#"
wmode="transparent"
maxfileselect=6 />
Process.cfm
<cfset path = #file_path# & "\" & #url.pro_num# >
<cffile
action="uploadall"
destination="#path#"
nameconflict="overwrite"
result="uploadedFiles" />
<!--- iterate over uploadedFiles result array and perform an insert for each record --->
<cfif IsDefined("uploadedFiles") and IsArray(uploadedFiles) and ArrayLen(uploadedFiles) gt 0>
<cfloop from="1" to="#ArrayLen(uploadedFiles)#" index="idx">
<cfset name = "pic" & idx>
<cfquery name="insertFileRecord" datasource="#application.dsn#">
update closeout set #name# = '#uploadedFiles[idx].serverfile#'
where pro_num = '#url.pro_num#' and type = '#url.type#'
</cfquery>
</cfloop>
</cfif>
Copy link to clipboard
Copied
Since uploadall acts asynchronously a separate call to process.cfm might be made for each file uploaded. This would result in the name variable being equal to "pic1" for every file uploaded.
Copy link to clipboard
Copied
I changed my database design to account for this "feature". It sucks a little but it's working now.
Thanks for your help.
Copy link to clipboard
Copied
Perhaps a UI with six file input controls labeled pic 1-6 would be better suited to your site. That would allow you to contol which file corresponds to pics 1-6.