【发布时间】:2014-03-20 18:12:18
【问题描述】:
这段代码曾经在 ColdFusion 9 中正常工作:
<cfif form.btnSaveImage EQ "Upload">
<cftry>
<cffile accept="image/*" action="upload" destination="C:\T" filefield="vcImageFile" nameconflict="overwrite">
<cfcatch type="Any">
<cfdump var="#cfcatch#" label="cfcatch">
</cfcatch>
</cftry>
</cfif>
<form action="<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>" method="post" name="frmImagesAdd" id="frmImagesAdd" enctype="multipart/form-data">
<label for="vcImageFile">Image File*:</label><br>
<input type="file" name="vcImageFile" id="vcImageFile" size="40" maxlength="255" message="Image file is required to upload."><br>
<input type="hidden" name="btnSubmit" value="Add Image">
<input name="btnSaveImage" type="submit" value="Upload">
</form>
问题在于 cffile 标记的 accept="image/*" 属性。在 ColdFusion 9 中,此通配符用于接受 MIME 类型以“image/”开头的任何文件。在 ColdFusion 10 中,我收到以下错误消息:
"上传文件 image/jpeg 的 MIME 类型或扩展名是 不被服务器接受。”
MimeType 值为“image/jpeg”,因此它应该与通配符一起使用。
我查看了wikidocs for the cffile tag,上面写着:
ColdFusion 10:对属性的修改接受}}
但是,它没有详细说明这些修改是什么!
查看upload action docs,它表示它将接受以逗号分隔的mime 类型列表。这是否意味着不再接受通配符?
【问题讨论】:
-
(编辑)如果你使用
strict=false会发生什么?不是您问题的答案,但您可能想阅读以下内容:Secure file uploads / Don't rely on cffile accept attribute。不确定是否仍然适用于 CF 10,仅供参考... -
我个人已经指定了我想接受的每种图像类型,如下所示:image/jpeg、image/pjpeg、image/png、image/gif。在我看来,这样做比使用通配符更好。
-
@volumeone - 我不知道 CF10 是否发生了变化,但在早期版本中,“接受”方法很容易破解,所以无论如何你都不应该依赖它。见上面的链接。
-
@Leigh, TYVM!!有关“不要依赖 cffile 接受属性”的信息的链接。我必须检查代码以确保不会发生这种情况!希望我能多次投票。