[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

trouble with renaming the uploaded files

Posted on 2010-09-12
5
Medium Priority
?
347 Views
Last Modified: 2012-05-10
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\inventory\">
<cfset filter = "image/jpg,image/jpeg,image/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.serverDirectory#/#fileUpload.serverfile#")>
      <!--- Read the image file into a variable called myImage. --->
      <cfimage action="read" source="#fileUpload.serverDirectory#/#fileUpload.serverfile#" name="myImage">
                  <cfset ImageResize(myImage,#form.width#,#form.height#,"HIGHESTQUALITY",1)>
              <cfset ImageResize(myImage,#form.fullwidth#,#form.fullheight#,"HIGHESTQUALITY",1)>
                   <cfset form.newImageName = fileUpload.serverFilename & "_front1_thumb." & fileUpload.serverFileExt>
            <cfimage source="#myImage#" action="write" destination="#path#/#form.newImageName#" overwrite="yes">    
     
      <cfelse>
          <cffile action="delete" file="#fileUpload.serverDirectory#/#fileUpload.serverFile#">
    </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
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 33660066
Could you please try the below code?

<cfset newImageName = "#fileUpload.serverFilename#_front1_thumb.#fileUpload.serverFileExt#">
            <cfimage source="#myImage#" action="write" destination="#path#/#newImageName#" overwrite="yes">    
0
 
LVL 16

Accepted Solution

by:
duncancumming earned 2000 total points
ID: 33665807
So right now you're doing:
<cfset form.newImageName = fileUpload.serverFilename & "_front1_thumb." & fileUpload.serverFileExt>
<cfimage source="#myImage#" action="write" destination="#path#/#form.newImageName#" overwrite="yes">    

But you want to do:
#numberformat(itemid,'0000')#_front1_thumb.jpg

Where does itemid come from?  Also it seems you'll be completely ditching any reference to the uploaded file name?  In which case why not just do:

<cfset newImageName = "#numberformat(itemid,'0000')#_front1_thumb.jpg">

<cfimage source="#myImage#" action="write" destination="#path#/#newImageName#" overwrite="yes">    
0
 
LVL 4

Expert Comment

by:sandy12879
ID: 33669541
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.serverFilename#_front1_thumb.#fileUpload.serverFileExt#">
            <cfimage source="#myImage#" action="write" destination="#path#/UNIQUEID#newImageName#" overwrite="yes">
This will ensure uniqueness for the file's having similar name.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 33681992
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.serverFileExt#     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.
0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 33710766
Thanks i found another way also, but urs is also cool
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

649 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