Fileinfo在php版本5.4.22和5.3.3上返回不同的mimetype

Fileinfo在php版本5.4.22和5.3.3上返回不同的mimetype,php,file,file-upload,mime-types,Php,File,File Upload,Mime Types,我正在本地服务器上通过mimetype编写自定义文件验证php版本是5.4.22,它返回“docx”文件mimetype“application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=binary”,这对我来说是正确的 但在我的服务器上有php版本5.3.3,它返回的“docx”文件mimetype“application/zip;charset=binary”不正确,我的验证在这里失败 请建议我必

我正在本地服务器上通过mimetype编写自定义文件验证php版本是5.4.22,它返回“docx”文件mimetype“application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=binary”,这对我来说是正确的

但在我的服务器上有php版本5.3.3,它返回的“docx”文件mimetype“application/zip;charset=binary”不正确,我的验证在这里失败

请建议我必须做什么,我应该升级服务器5.3.3上的php版本到php的最新版本

function hook_file_validate($file) {
    $errors = array();
    //Getting filename
    $extn = explode(".", $file->filename);
    //Getting file mimetype
    $finfo = new finfo(FILEINFO_MIME);
    $type = $finfo->file($file->uri);

    if ($extn[1]=='txt' && $type!='text/plain; charset=us-ascii'){
        $errors[] = t("Please upload valid file");
    } else
    if ($extn[1]=='doc' && $type!='application/msword; charset=binary'){
        $errors[] = t("Please upload valid file.");
    } else
    if ($extn[1]=='pdf' && $type!='application/pdf; charset=binary'){
        $errors[] = t("Please upload valid file.");
    } else
    if ($extn[1]=='xls' && $type!='application/octet-stream; charset=binary'){
        $errors[] = t("Please upload valid file.");
    } else
    if ($extn[1]=='docx' && $type!='application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=binary')    {
        $errors[] = t("Please upload valid file.");
    }

    return $errors;
}

获取application/zip mime类型后检查文件扩展名。这是密码

$arrayZips = array("application/zip", "application/x-zip", "application/x-zip-compressed");
$arrayExtensions = array(".pptx", ".docx", ".dotx", ".xlsx");
$file = 'path/to/file.xlsx';
$original_extension = (false === $pos = strrpos($file, '.')) ? '' : substr($file, $pos);
$finfo = new finfo(FILEINFO_MIME);
$type = $finfo->file($file);
if(in_array($type, $arrayZips) && in_array($original_extension, $arrayExtensions)){
    return $original_extension;
}

docx文件实际上是一个zip文件,但扩展名不同。可能发生的情况是,在最新版本的php中添加了检查“zip”内容的功能,因此我必须升级php版本。或者更改您的验证代码,使其与两个版本兼容。请阅读“用户提供的注释”:可能重复的