Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file extension when renaming file with cffile

Tags:

coldfusion

I'm using a cffile tag to upload my file and resave it with a new name. My issue is that the file could be a few different formats and I don't know how to detect the file extension. I'm using the code below:

<cfset ui = createUUID()>
<cffile 
  action="upload" 
  accept="video/x-flv, video/mp4, video/x-msvideo"
  destination="e:\www2\uploads\#ui#.#cffile.ServerFileExt#" 
  nameconflict="makeunique" 
  filefield="form.file"
>

It's telling me that cffile is undefined.

like image 437
The Muffin Man Avatar asked Feb 15 '11 22:02

The Muffin Man


1 Answers

I recommend uploading first, then renaming:

<cfset ui = createUUID()>
<cffile 
  action="upload" 
  accept="video/x-flv, video/mp4, video/x-msvideo" 
  destination="e:\www2\uploads\" 
  nameconflict="makeunique" 
  filefield="form.file"
/>
<cffile 
  action="rename" 
  source="e:\www2\uploads\#cffile.serverFileName#" 
  destination="e:\www2\uploads\#ui#.#cffile.serverFileExt#"
/>
like image 163
scrittler Avatar answered Nov 09 '22 19:11

scrittler