不正确的MIME类型从PHP [英] Incorrect mime-type from PHP
问题描述
当上传的Power Point 2000文档(.PPT)在微软的Power Point创造了它是一个返回的应用程序/ vnd.ms-办公室MIME类型。我希望应用程序/ vnd.ms - PowerPoint中回来的:
When uploading a Power Point 2000 document (.ppt) created in Microsoft Power Point it is a returning a mime type of application/vnd.ms-office. I would expect application/vnd.ms-powerpoint to come back from:
<?php
$finfo = new finfo(FILEINFO_MIME);
$mime_type = $finfo->file($filepath);
// strip off the mime encoding information
$mime_type = substr($mime_type, 0, strpos($mime_type, ';'));
任何想法,为什么这也许是这样吗?
Any ideas why this maybe the case?
我运行以下内容:
- 的Ubuntu
- PHP 5.2
- 的Apache 2
推荐答案
finfo
ins't 100%可靠的,尤其是当它涉及到Microsoft Office文档。我不认为这是一个容易解决您的解决方案。你可以尝试,如果返回应用程序/ vnd.ms办公室
,然后还检查文件的扩展名是 .PPT
,如果是,设置MIME类型应用程序/ vnd.ms - PowerPoint演示
。当然,延期是没有意义的,但那些使用微软,有一个很好的机会和扩展名的文件 .PPT
是PowerPoint,而不是别的。
finfo
ins't 100% reliable, especially when it comes to Microsoft Office documents. I don't think there is an easy fix to your solution. You might try, if it returns application/vnd.ms-office
, then additionally check if the extension of the file is .ppt
, and if it is, set the mime type to application/vnd.ms-powerpoint
. Of course an extension is meaningless, but those using Microsoft, there is a good chance a file with extension .ppt
is a powerpoint and not anything else.
这篇关于不正确的MIME类型从PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!