2
votes

I'm trying to have a simple camera file upload app to where when I take a picture and it uploads to my web server; as well as renaming the file in the process. I have managed to figure out how to upload the file with action="upload". However, when I create another cffile action="rename" and start adding cffile parameters it breaks my page.

I know upload is working cause when I check my server, the file is getting uploaded even though my page is breaking. Also I know i have no validation on this as im just trying to get the functionality working then I'll perform validation.

Here is what I tried:

HTML

<form method="POST" enctype="multipart/form-data" action="testupload.cfm">
  <input type="file" name="fileUpload" accept="image/*" capture="camera">
  <input type="submit" value="Upload">
</form>

ColdFusion:

<cfset newfileName = "test">
<cffile 
  action="upload" 
  accept="image/jpg, image/jpeg, image/png" 
  destination="C:\uploads\" 
  nameconflict="makeunique" 
  filefield="form.fileUpload"
/>
<cffile 
  action="rename" 
  source="C:\uploads\#cffile.serverFileName#" 
  destination="C:\uploads\#newfileName#.#cffile.serverFileExt#"
/>
1

1 Answers

3
votes

Try this (concatenate strings):

<cfset newfileName = "test">
<cffile 
  action="upload" 
  accept="image/jpg, image/jpeg, image/png" 
  destination="C:\uploads\" 
  nameconflict="makeunique" 
  filefield="form.fileUpload"
/>

<cfset sourcePath = "C:\uploads\" & #cffile.serverFileName# & "." & #cffile.serverFileExt# />
<cfset destinationPath = "C:\uploads\" & #newFileName# & "." & #cffile.serverFileExt# />

<cffile 
  action="rename" 
  source="#sourcePath#" 
  destination="#destinationPath#"
/>