Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Prepend 'timeLastModified' to uploaded files

Posted on 2009-02-17
9
Medium Priority
?
629 Views
Last Modified: 2013-12-24
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

0
Comment
Question by:rrattie
  • 5
  • 4
9 Comments
 
LVL 2

Author Comment

by:rrattie
ID: 23661059
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
 
LVL 19

Expert Comment

by:Jones911
ID: 23661277
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
 
LVL 2

Author Comment

by:rrattie
ID: 23662606
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 19

Expert Comment

by:Jones911
ID: 23662630
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
 
LVL 2

Author Comment

by:rrattie
ID: 23662703
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
 
LVL 19

Expert Comment

by:Jones911
ID: 23662751
What you need to do is upload it then rename it.
0
 
LVL 2

Author Comment

by:rrattie
ID: 23662824
How do you do that?
0
 
LVL 19

Accepted Solution

by:
Jones911 earned 1000 total points
ID: 23662905
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
 
LVL 2

Author Closing Comment

by:rrattie
ID: 31547840
Jones911 You Rock!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question