Reputation: 13
I am new to ColdFusion. I am using ColdFusion 10. I am trying to upload multiple image files using cffileupload
. I am able to upload files as expected. But I would like to get the metadata before uploading and get the clientFileDirectory
of the uploaded files. PFB code
fileupload.cfm
<cffileupload
name = "uploadDemo"
url="uploadSelectedFiles.cfm"
progressbar="true"
addButtonLabel = "Select File(s)"
clearButtonLabel = "Clear"
width="500"
height="400"
title="Choose Files To Upload"
maxUploadSize="1"
maxFileSelect="10"
extensionfilter="*.gif,*.jpg,*.png,*.doc"
uploadButtonLabel="Upload"
onComplete="previewfile"
>
uploadSelectedFiles.cfm
<cffile action="uploadall"
destination="#expandpath('.')#"
nameconflict="makeUnique"
result="uploadResult"
/>
<cfoutput>try</cfoutput>
<cfdump var="#cffile#">
But cffile.clientDirectory
throws a Status code :500 (unable to upload files too....). One more thing, I am not able to view the 'try' string output in the main page (file upload page).
EDITED: ADDED MORE INFO
Thank you so much for the reply.
I am looking for cffile.clientDirectory (uploadResults.clientDirectory) information, but unable to get it.PLEASE HELP....I am in dire need of that info. I am not getting it for any uploaded file. PFB my trials.
I tried
<cfdump var="#uploadResult#" label="Upload Meta Data" output="#expandPath( './log.txt' )#" format="text" />
and the logs are available.
log.txt
Upload Meta Data - array - Top 1 of 1 rows
1) [struct]
ATTEMPTEDSERVERFILE: cat.jpg
CLIENTDIRECTORY: [empty string]
CLIENTFILE: cat.jpg
CLIENTFILEEXT: jpg
CLIENTFILENAME: cat
CONTENTSUBTYPE: octet-stream
CONTENTTYPE: application
DATELASTACCESSED: {d '2013-05-20'}
FILEEXISTED: YES
FILESIZE: 446759
FILEWASAPPENDED: NO
FILEWASOVERWRITTEN: YES
FILEWASRENAMED: NO
FILEWASSAVED: YES
OLDFILESIZE: 446759
SERVERDIRECTORY: E:\Inetpub\wwwroot\cdd\Portfolio\eKris
SERVERFILE: cat.jpg
SERVERFILEEXT: jpg
SERVERFILENAME: cat
TIMECREATED: {ts '2013-05-20 17:35:57'}
TIMELASTMODIFIED: {ts '2013-05-20 17:35:57'}
Can you please help me get the clientDirectory info...?
Upvotes: 0
Views: 509
Reputation: 13548
As @Leigh mentioned, typically you are only concerned with the name and location of the uploaded file on the server. The directory on the client's machine is irrelevant. Furthermore I believe the empty field being returned is due to the enhanced security of modern browsers. It would be considered a security breach to expose that information from the client's machine. I assume that Adobe has only left this feature in for backwards compatibility.
I have found three old posts that discuss having inconsistent results with the cffile.clientDirectory
field. They all happen to be back from 2008. They all mention that each of the browsers behave differently. They all mention that only Internet Explorer ever returns anything in the cffile.clientDirectory
field. The posts mention that they were using Internet Explorer 7. Even back then (according to one of the posts) the current versions of Firefox, Netscape and Safari were not returning this information and I don't believe Chrome existed yet. I would conclude that Microsoft finally caught up with the other browsers and are no longer supplying this information.
Here are the three posts that I mentioned:
Upvotes: 1
Reputation: 28873
get the clientFileDirectory of the uploaded files
<cffile action="uploadall" result="uploadResult" ...>
I see a few problems:
You specified a "result" name, so the file properties are being placed in a variable named uploadResult
, instead of cffile
.
<cffile action="uploadAll">
is designed to process multiple files. So it returns an array of file properties, not just a single structure. So you must loop through the array to access the properties of each file.
The actual property is named clientDirectory
, not clientFileDirectory
.
But, that said .. the location of the file on the client is usually not relevant. In most web applications, you are just concerned with the name and location of the uploaded file on the server, so you can make it available for viewing/downloading later. So I suspect you may have meant to use the serverXXX
variables instead ? ie
<cfloop array="#uploadResult#" index="fileProp">
serverFile: <cfdump var="#fileProp.serverFile#">
serverDirectory: <cfdump var="#fileProp.serverDirectory#">
</cfloop>
I would like to get the metadata before uploading
The <cffile action="uploadAll">
code executes after the file(s) are uploaded. All it really does is moves and renames the file(s). So technically, you cannot obtain that information before uploading - only afterward.
Upvotes: 0
Reputation: 47
<cfif structKeyExists(form,"submit")> <br/>
<cffile action="uploadall" destination="#expandpath('./upload')#">
</cfif> <br/>
<cfform action="#cgi.script_name#" enctype="multipart/form-data"> <br/>
<cfinput type="file" name="attachment1"> <br/><br>
<cfinput type="file" name="attachment2"> <br/><br>
<cfinput type="file" name="attachment3"> <br/><br>
<cfinput type="submit" name=" submit" value="submit"> <br/>
</cfform>
Please check this.
Upvotes: 0