Link to home
Start Free TrialLog in
Avatar of rrattie
rrattieFlag for United States of America

asked on

Prepend 'timeLastModified' to uploaded files

I have a form in a coldfusion page that uploads files to a directory, when the files are uploaded I want the 'timeLastModified' to be prepended to the file name so that the files can be easily identified as being part of the same group.

I have tried the code below in my CFFILE tag, but I just get:

Element TIMELASTMODIFIED is undefined in CFFILE

<!---File Upload Script  START--->
<!--- create an array for the file details: --->
<cfset files = ArrayNew(1)>
<!---File Upload Script  START--->
 
<cfloop from="1" to="6" index="i" >
  <cfif isdefined("FORM.uploadfile"&i) and FORM["uploadfile"&i] GT "" >
    <cffile action="UPLOAD" filefield="FORM.uploadfile#i#" destination="E:\intranet\cf_portal\document_uploads\#cffile.timeLastModified##cffile.ServerFileName#.#cffile.ServerFileExt#" nameconflict="makeunique" accept="image/bmp, image/jpg, image/jpeg, image/pjpeg, image/gif, application/msword, video/mpeg, video/quicktime, application/pdf, application/vnd.ms-powerpoint, text/rtf, image/tiff, application/vnd.ms-excel">
    <cfoutput> File#i#: #cffile.ServerDirectory#\#cffile.ServerFileName#.#cffile.ServerFileExt#<br>
    </cfoutput>
    <!--- add the file info to our array --->
    <cfset ArrayAppend(files, cffile)>
  </cfif>
</cfloop>
<!---File Upload Script END--->

Open in new window

Avatar of rrattie
rrattie
Flag of United States of America image

ASKER

I have the format for the time prepared.. but I don't know how to add it into the mix.



example output: 2009_04_17_11_04_48
<cfset currentTime = now()>
 
#TimeFormat(currentTime, 'yyyy_mm_dd_HH_mm_ss')#

Open in new window

Avatar of Jones911
Jones911

Have a look.
<cfset currentTime = TimeFormat(now(), 'yyyy_mm_dd_HH_mm_ss')>
 
 <cffile action="UPLOAD" filefield="FORM.uploadfile#i#" destination="E:\intranet\cf_portal\document_uploads\#currentTime ##cffile.timeLastModified##cffile.ServerFileName#.#cffile.ServerFileExt#"   .....

Open in new window

Avatar of rrattie

ASKER

The cfset code  helped, but I still get "Element SERVERFILENAME is undefined in CFFILE" when I try and use the rest of the code. I removed the TIMELASTMODIFIED part, since the now() piece seemed to work fine.

Can I access/use  the Server.FileName at that point? or is it still empty at that point?
<cfset currentTime = TimeFormat(now(), 'yyyy_mm_dd_HH_mm_ss')>

Open in new window

Try this then
 <cffile action="UPLOAD" filefield="FORM.uploadfile#i#" destination="E:\intranet\cf_portal\document_uploads\#currentTime##cffile.ServerFileName#.#cffile.ServerFileExt#"   .....

Open in new window

Avatar of rrattie

ASKER

I still get an error with that.



Element SERVERFILENAME is undefined in CFFILE.  
 
  
The error occurred in E:\intranet\cf_portal\ssrResults.cfm: line 45
 
43 : <cfloop from="1" to="6" index="i" >
44 :   <cfif isdefined("FORM.uploadfile"&i) and FORM["uploadfile"&i] GT "" >
45 :     <cffile action="UPLOAD" filefield="FORM.uploadfile#i#" destination="E:\intranet\cf_portal\document_uploads\#currentTime##cffile.ServerFileName#.#cffile.ServerFileExt#" nameconflict="makeunique" accept="image/bmp, image/jpg, image/jpeg, image/pjpeg, image/gif, application/msword, video/mpeg, video/quicktime, application/pdf, application/vnd.ms-powerpoint, text/rtf, image/tiff, application/vnd.ms-excel">
46 :     <cfoutput> File#i#: #cffile.ServerDirectory#\#cffile.ServerFileName#.#cffile.ServerFileExt#<br>
47 :     
 

Open in new window

What you need to do is upload it then rename it.
Avatar of rrattie

ASKER

How do you do that?
ASKER CERTIFIED SOLUTION
Avatar of Jones911
Jones911

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rrattie

ASKER

Jones911 You Rock!!