如何在使用cffile重命名文件时获取文件扩展名
问题描述:
我正在使用cffile
标记上传我的文件并使用新名称重新保存。我的问题是该文件可能是几种不同的格式,我不知道如何检测文件扩展名。我使用下面的代码:如何在使用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是未定义的。
答
我建议您上传,然后再重命名:
<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#"
/>
+0
谢谢你的工作。 – 2011-02-15 22:33:01
答
我发现创造了这个真棒功能由Ryan Stille
应该做的一切你需要
我用它来得到扩展,然后我刚刚创建了一个带有UUID的文件名
<cffile action="upload" destination="file://upload_#createUUID()#.#fileExt#" nameconflict="makeunique" result="#formField#">
“CFFILE”变量只有在上传之后才会填充。正如scrittler所说,先上传,然后重命名。 – Leigh 2011-02-15 22:20:05