开发者

How to get file extension when renaming file with cffile

开发者 https://www.devze.com 2023-02-11 10:37 出处:网络
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 c

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开发者_StackOverflow社区\uploads\#ui#.#cffile.ServerFileExt#" 
  nameconflict="makeunique" 
  filefield="form.file"
>

It's telling me that cffile is undefined.


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


I found this awesome function created by Ryan Stille

It should do everything you need

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

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

精彩评论

暂无评论...
验证码 换一张
取 消