使用cffile重命名文件时如何获取文件扩展名

时间:2011-02-15 22:05:12

标签: coldfusion

我正在使用cffile标记上传我的文件并使用新名称重新保存。我的问题是该文件可能是几种不同的格式,我不知道如何检测文件扩展名。我正在使用以下代码:

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

它告诉我,cffile未定义。

2 个答案:

答案 0 :(得分:12)

我建议先上传,然后重命名:

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

答案 1 :(得分:0)

我找到了由Ryan Stille

创建的这个很棒的功能

它应该做你需要的一切

我用它来获取扩展名然后我刚创建了一个带有UUID的文件名

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