How to get file extension when renaming file using cffile

I use the tag cffileto upload my file and save it with a new name. My problem is that the file can be in several different formats, and I do not know how to determine the file extension. I am using the following code:

<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"
>

This tells me that cffile is undefined.

+5
source share
2 answers

I recommend downloading first and 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#"
/>
+12
source

I found this amazing feature created by Ryan Stille

He must do whatever you need.

I used it to get the extension, then I just created a file name with UUID

<cffile action="upload" destination="file://upload_#createUUID()#.#fileExt#"  nameconflict="makeunique" result="#formField#">
0
source

All Articles