Renaming file after uploading in Coldfusion

Picture Upload FTP ServerI 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" .

Thanks.


-------- 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>
LVL 1
sgleeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgrafxCommented:
ok so start here:
<form action="actionpage.cfm" method="post" ENCTYPE="multipart/form-data">
      <input type="text" name="itemid" value="123456"><br />
      <input type="file" name="AttachFile"><br />
      <input type="submit" value="Submit">
</form>

then here is your action page (actionpage.cfm):
<cfset filelocation="d:\websites\mysite\myfolder\"><!--- set your destination for uploads --->
<cftry>
<cfif len(trim(Form["AttachFile"]))>      
      <CFFILE ACTION="UPLOAD"
            FILEFIELD="AttachFile"
            DESTINATION="#variables.filelocation#"
            NAMECONFLICT="makeunique">
      <cfset filename=form.itemid & "." & cffile.serverFileExt>
      <cffile action="rename" source="#variables.filelocation##cffile.serverfile#" destination="#variables.filelocation##variables.filename#">      
</cfif>
<cfcatch>
</cfcatch></cftry>

if any questions please ask ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sgleeAuthor Commented:
ItemNo and PictureFile Renamed in DestinationFTP Folder after picture is uploaded and renamedIt 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\">
<cftry>
<cfif len(trim(Form["AttachFile"]))>      
      <CFFILE ACTION="UPLOAD"
            FILEFIELD="AttachFile"
            DESTINATION="#variables.filelocation#"
            NAMECONFLICT="makeunique">
      <cfset filename=form.ItemNo & "." & cffile.serverFileExt>
<cfoutput>FileName: #filename# <BR>
          Folder Location:#variables.filelocation#<BR>
#variables.filelocation##cffile.serverfile#<BR>
#variables.filelocation##variables.filename#<BR>
</cfoutput>
      <cffile action="rename" source="#variables.filelocation##cffile.serverfile#" destination="#variables.filelocation##variables.filename#">      
</cfif>
<cfcatch>
</cfcatch></cftry>
0
dgrafxCommented:
yes the trailing slash in the filelocation is very important
0
dgrafxCommented:
Did my post solve the problem?
Is there anything else you need in this question?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.