rrattie
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
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--->
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#" .....
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?
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')>
Try this then
<cffile action="UPLOAD" filefield="FORM.uploadfile#i#" destination="E:\intranet\cf_portal\document_uploads\#currentTime##cffile.ServerFileName#.#cffile.ServerFileExt#" .....
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 :
What you need to do is upload it then rename it.
ASKER
How do you do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Jones911 You Rock!!
ASKER
example output: 2009_04_17_11_04_48
Open in new window