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

LVL 2
rrattieAsked:
Who is Participating?
 
Jones911Commented:
This shoudl do it.
<cfset currentTime = TimeFormat(now(), 'yyyy_mm_dd_HH_mm_ss')> 
 
<cffile action="UPLOAD" filefield="FORM.uploadfile#i#" destination="E:\intranet\cf_portal\document_uploads\" 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">
 
<cffile action="rename" source="E:\intranet\cf_portal\document_uploads\#cffile.serverFile#" destination="E:\intranet\cf_portal\document_uploads\#currentTime#_#cffile.serverFile" />

Open in new window

0
 
rrattieAuthor Commented:
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

0
 
Jones911Commented:
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

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
rrattieAuthor Commented:
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

0
 
Jones911Commented:
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

0
 
rrattieAuthor Commented:
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

0
 
Jones911Commented:
What you need to do is upload it then rename it.
0
 
rrattieAuthor Commented:
How do you do that?
0
 
rrattieAuthor Commented:
Jones911 You Rock!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.