验证上传的文件 [英] Verifying Uploaded File
问题描述
我正在处理一个需要用户上传Microsoft Word文档的文档。除了检查文件扩展名是.doc还是.docx之外,还有其他什么方法可以验证上传的文件实际上是Microsoft Word文档,而不是任何其他文件其他文件重命名为.doc或.docx扩展名。
在此先感谢。
如果你不使用PHP 5.3, mime_content_type
功能可能会让你感兴趣。
如果您使用的是PHP 5.3和/或可以安装PECL扩展,新的Fileinfo库应该做这个工作;请参阅 finfo_file
了解更多信息。
在给定的例子中,一个标识的MIME类型是 application / vnd.ms-excel
;所以,有一点运气,它应该能够处理MS Word文件; - )
I am working on a document that requires a user to upload a Microsoft Word Documents.
Apart from checking the file extension to be .doc or .docx, is there any other way i can verify that the uploaded file is actually a Microsoft Word Document and not any other file renamed to a .doc or .docx extension.
Thanks in advance.
If your are not using PHP 5.3, the mime_content_type
function might interest you.
If you are using PHP 5.3 and/or can install PECL extensions, the new Fileinfo library should do the job ; see finfo_file
for more informations.
In the given example, one of the identified mime types is "application/vnd.ms-excel
" ; so, with a bit of luck, it should be able to deal with MS Word files too ;-)
这篇关于验证上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!