PHP 5.3.5 fileinfo()MS Office 2007文件的MIME类型-magic.mime更新了吗? [英] PHP 5.3.5 fileinfo() MIME Type for MS Office 2007 files - magic.mime updates?

查看:97
本文介绍了PHP 5.3.5 fileinfo()MS Office 2007文件的MIME类型-magic.mime更新了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP上传中,我正在尝试验证要上传的文件的MIME类型,以匹配该应用程序的有效MIME类型集.尝试使用fileinfo()确定Office 2007文件的MIME类型时,不会将其检测为适当的MIME类型.而是MIME类型响应为"application/zip"

Office文档MIME类型: http://filext.com/faq/office_mime_types.php

示例PHP代码:

$ oFileInfo =新的finfo(FILEINFO_MIME_TYPE);

$ sMimeType = $ oFileInfo->文件($ _FILES ['Filedata'] ['tmp_name']);

回显$ sMimeType;

服务器设置信息:

  • 操作系统:Windows Server 2003 32位
  • 网络服务器:IIS 6.0
  • PHP:使用FastCGI 1.5的5.3.5(线程安全)
  • 文件:magic.mime
    • darko在uvcms点com上的示例2008年4月16日09:35
      • 链接:php.net/manual/en/fileinfo.installation.php
    • 大小:517 KB
    • 来源:Source Forge:GNU32-FileType gnuwin32.sourceforge.net/packages/filetype.htm

从网络服务器下载时,我发现了很多帖子都提到了较新的Office格式的问题.在所有这些示例中,我都找不到一个说明将新MIME类型添加到现有magic.mime文件中的方法,或指向已经包含Microsoft Office 2007+ MIME类型的magic.mime文件的链接的地方.感谢您的协助.

解决方案

  1. 是的,您应该更新magic.mime.

大声笑,是的,只需更新它,问题就解决了. 不幸的是,魔术mime类型系统似乎无法查看实际的文件内容,并且由于文件已压缩,因此无法解压缩(并查看哪个文件?)

例如,有人建议编写一个函数来解压缩压缩文件,然后检查是否存在"DocProps"目录.但这会给生产服务器带来另一种攻击媒介.

On a PHP upload, I'm trying to validate the MIME Type of the files being uploaded to match a valid set of MIME types for the application. When attempting to use the fileinfo() to determine the MIME type of an Office 2007 file it is NOT detecting as their appropriate MIME Types. Instead the MIME type response is "application/zip"

Office Document MIME types: http://filext.com/faq/office_mime_types.php

Example PHP Code:

$oFileInfo = new finfo( FILEINFO_MIME_TYPE );

$sMimeType = $oFileInfo -> file( $_FILES['Filedata']['tmp_name'] );

echo $sMimeType;

Server Setup Info:

  • OS: Windows Server 2003 32-bit
  • Webserver: IIS 6.0
  • PHP: 5.3.5 (Thread Safe) using FastCGI 1.5
  • File: magic.mime
    • Example by darko at uvcms dot com 16-Apr-2008 09:35
      • Link: php.net/manual/en/fileinfo.installation.php
    • Size: 517 KB
    • Source: Source Forge: GNU32 - FileType gnuwin32.sourceforge.net/packages/filetype.htm

I've found numerous posts which refer to issues with the newer Office format when downloading from a webserver. In all these examples I haven't found anywhere that illustrates a manor of adding the new MIME types to an existing magic.mime file, or a link to a magic.mime file that already contains the Microsoft Office 2007+ MIME types. Thanks for your assistance.

解决方案

  1. Yes, you should update magic.mime.

lol, yeah, just update it, problem solved. Unfortunately, it looks like the magic mime type systems works off of looking at the actual file contents, and because the file is compressed, it can't uncompress (and look at which file?)

someone suggested writing a function to unzip compressed files and then checking for the existence of a "DocProps" directory, for instance. But this would introduce another vector of attack to the production server.

这篇关于PHP 5.3.5 fileinfo()MS Office 2007文件的MIME类型-magic.mime更新了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆