Coast Line
asked on
trouble with renaming the uploaded files
i have the following code which works fine but my isse is that how can i rename the file to a specific format
here is my code!
<cftry>
<cfset path = "#filepath#\images\invento ry\">
<cfset filter = "image/jpg,image/jpeg,imag e/pjpeg">
<cfif form.userfile IS NOT "">
<cffile action="upload" fileField="userfile" destination="#path#" result="fileUpload" nameconflict="overwrite" accept="#filter#">
<cfif fileUpload.fileWasSaved>
<!--- Determine whether the saved file is a valid image file. --->
<cfif IsImageFile("#fileUpload.s erverDirec tory#/#fil eUpload.se rverfile#" )>
<!--- Read the image file into a variable called myImage. --->
<cfimage action="read" source="#fileUpload.server Directory# /#fileUplo ad.serverf ile#" name="myImage">
<cfset ImageResize(myImage,#form. width#,#fo rm.height# ,"HIGHESTQ UALITY",1) >
<cfset ImageResize(myImage,#form. fullwidth# ,#form.ful lheight#," HIGHESTQUA LITY",1)>
<cfset form.newImageName = fileUpload.serverFilename & "_front1_thumb." & fileUpload.serverFileExt>
<cfimage source="#myImage#" action="write" destination="#path#/#form. newImageNa me#" overwrite="yes">
<cfelse>
<cffile action="delete" file="#fileUpload.serverDi rectory#/# fileUpload .serverFil e#">
</cfif>
</cfif>
i want to convert the upload file as this format!
#numberformat(itemid,'0000 ')#_front1 _thumb.jpg
I am really lost here! please guide
here is my code!
<cftry>
<cfset path = "#filepath#\images\invento
<cfset filter = "image/jpg,image/jpeg,imag
<cfif form.userfile IS NOT "">
<cffile action="upload" fileField="userfile" destination="#path#" result="fileUpload" nameconflict="overwrite" accept="#filter#">
<cfif fileUpload.fileWasSaved>
<!--- Determine whether the saved file is a valid image file. --->
<cfif IsImageFile("#fileUpload.s
<!--- Read the image file into a variable called myImage. --->
<cfimage action="read" source="#fileUpload.server
<cfset ImageResize(myImage,#form.
<cfset ImageResize(myImage,#form.
<cfset form.newImageName = fileUpload.serverFilename & "_front1_thumb." & fileUpload.serverFileExt>
<cfimage source="#myImage#" action="write" destination="#path#/#form.
<cfelse>
<cffile action="delete" file="#fileUpload.serverDi
</cfif>
</cfif>
i want to convert the upload file as this format!
#numberformat(itemid,'0000
I am really lost here! please guide
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to have a unique ID associated while renaming your Images and u can use the same piece of code mentioned by ansudhindra
<cfset newImageName = "#fileUpload.serverFilenam e#_front1_ thumb.#fil eUpload.se rverFileEx t#">
<cfimage source="#myImage#" action="write" destination="#path#/UNIQUE ID#newImag eName#" overwrite="yes">
This will ensure uniqueness for the file's having similar name.
<cfset newImageName = "#fileUpload.serverFilenam
<cfimage source="#myImage#" action="write" destination="#path#/UNIQUE
This will ensure uniqueness for the file's having similar name.
Suggestion, I recommend renaming the file on the server completely remove the client's file name (as Duncan suggested).
There are several characters that can be in a file name that will not be allowed on the server or will cause issues when handling through coldfusion. I always rename the file to just the ID associated with the database record #file_id#.#fileUpload.serv erFileExt# That makes handling the file much easier.
Simply save the client file name in your database, when downloading the file back to the user (if you ever need to) you can use their original file name again so they never need to know the name of the file on your server.
There are several characters that can be in a file name that will not be allowed on the server or will cause issues when handling through coldfusion. I always rename the file to just the ID associated with the database record #file_id#.#fileUpload.serv
Simply save the client file name in your database, when downloading the file back to the user (if you ever need to) you can use their original file name again so they never need to know the name of the file on your server.
ASKER
Thanks i found another way also, but urs is also cool
<cfset newImageName = "#fileUpload.serverFilenam
<cfimage source="#myImage#" action="write" destination="#path#/#newIm