Link to home
Start Free TrialLog in
Avatar of cpwilson
cpwilson

asked on

Upload File, Rename and Store in Database

I need to upload a file, rename it to include the original file name and the last name of the person who uploaded it, then store the file with the new name in the database. Currently using the following but not working
 <cfset the_idcard = "">
<cffile action="upload" destination="#application_root#\images\memberid\" filefield="form.idcard" nameconflict="makeunique">
<cfset the_idcard = "#file.serverFile#">
<cffile action="rename" source="#application_root#\images\memberid\#the_idcard#" destination="#application_root#\images\memberid\#lastname#-#the_idcard#" attributes="normal">
 <cfset the_idcard = '#file.serverFile#'>
Avatar of Charlie Arehart
Charlie Arehart

Please clarify what's "not working". Did you get an error? Did it produce the wrong file name? Have you used Debugging techniques to output the value of all the variables involved? That may help you (or us) resolve whatever is amiss. 
ASKER CERTIFIED SOLUTION
Avatar of cpwilson
cpwilson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For the sake of anyone in the future who wonders what the asker did that solved their own problem, it's that they changed the last line in their code, from:

 <cfset the_idcard = '#file.serverFile#'>

Open in new window


to

<cfset the_idcard = '#form.lastname#-#file.serverFile#'>

Open in new window

So they just prepended the incoming form field for last name to the name of the file, which apparently is what they "store in the database" and that was "not working".