Link to home
Start Free TrialLog in
Avatar of sglee

asked on

Renaming file after uploading in Coldfusion

User generated image User generated imageI have a CF page where I can open Windows Explorer when [browse] button is clicked and select the picture file and upload to the FTP server along with additional information such as Items No, Category ID ... etc. (please see File Upload screenshot)

The picture file names on iPad are like Image1.jpg, Image2.jpg,  ImageNN.jpg ... etc. (please see in the FTP server screenshot) when they are uploaded to FTP server.

My question How I can rename this picture file names automatically so that they begin with Item number.jpg when or during they are uploaded?

For example, as seen in File Upload Screenshot, the picture file name on the local device is "Blova_Marine_Brown.jpg" and Item No for this is 9112. So I like to see "9112.jpg" in FTP server instead of "Blova_Marine_Brown.jpg".

Renaming these ImageNN.jpg files on iPad before uploading is not an option and here is the current code.
When I displayed <cfoutput>#file_path#</cfoutput>, it had some long "temporary" name instead of "Blova_Marine_Brown.jpg" .


-------- upload_photo1.cfm --------
<h3>Picture Upload </h3></font>
Click [BROWSE] and select a picture:

          <CFform action="upload_photo2.cfm" method="POST" name="frmupload" enctype="multipart/form-data">
            <CFINPUT type="file" name="file_path">&nbsp;&nbsp;

-------- upload_photo2.cfm --------

            <cfif isdefined("form.submit_upload")>
                  <cffile action="UPLOAD" filefield="file_path" destination="D:\home\XXX\wwwroot\imageupload\single" nameconflict="MAKEUNIQUE">
                        <h3>File Uploaded Successfully!</h3>
Avatar of dgrafx
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sglee


User generated imageUser generated imageUser generated imageIt worked great! I had to add "\" at the end of folder path to separate file name from folder path(...\multiple").

<cfset filelocation="D:\home\MySite\wwwroot\imageupload\multiple\">
<cfif len(trim(Form["AttachFile"]))>      
      <cfset filename=form.ItemNo & "." & cffile.serverFileExt>
<cfoutput>FileName: #filename# <BR>
          Folder Location:#variables.filelocation#<BR>
      <cffile action="rename" source="#variables.filelocation##cffile.serverfile#" destination="#variables.filelocation##variables.filename#">      
yes the trailing slash in the filelocation is very important
Did my post solve the problem?
Is there anything else you need in this question?