0

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

Sree
  • 13
  • 8
  • What operating system is your ColdFusion server running on? What operating system is your client computer running on? In your log.txt example, what was the location of the client file you chose to upload? Which browser did you use? – Miguel-F May 21 '13 at 12:26
  • RE: *I am looking for cffile.clientDirectory information* Why? (There is not much you can do with it from the server or browser, without special permissions). What is your use case? – Leigh May 21 '13 at 13:47

3 Answers3

1

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:

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
0
<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.

Matt Busche
  • 14,216
  • 5
  • 36
  • 61
  • What does that do differently than their current code? Can you elaborate? – Leigh May 20 '13 at 15:01
  • Hi Ramalinga Raju, Thanks for your reply, but I am looking for multiple file upload , by selecting multiple files using shift key. So your example will not fit my requirement. Anyways thanks... – Sree May 21 '13 at 00:31
0

get the clientFileDirectory of the uploaded files

<cffile action="uploadall" result="uploadResult" ...>

I see a few problems:

  1. You specified a "result" name, so the file properties are being placed in a variable named uploadResult, instead of cffile.

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

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

Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103
  • Thank you so much Leigh for the detailed explaination. I have edited my question and added more info on what I tried later.Firstly, if I use in uploadSelectedFiles.cfm I am not able to see anything on the upload screen (main page nothing is displayed ). I tried the cfloop code you have mentioned above for clientDirectory, but for all images I get only empty string. Please see the code in the next comment. – Sree May 21 '13 at 00:35
  • serverFile: serverDirectory: – Sree May 21 '13 at 00:40
  • (Edit) @Sree - Miguel-F beat me to it, but I was going to say something similar. Not all browsers will expose that information - most will not. The fact that IE ever did (in any version) was an "iffy" security practice IMO. AFAIK, it was **never** fully supported as it violates browser security restrictions. You cannot depend on it being available. Not unless you are using a special control like a signed applet, etcetera and the user has explicitly granted the control special access. Can you elaborate on why you think you need this value? – Leigh May 22 '13 at 14:01