PHP File Upload finfo MIME type not detecting correctly?

I am checking file MIME types of uploaded files and forcing extensions as so:

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['attachment']['tmp_name']);

if ($mime == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
    $extension = ".docx";
} else if ($mime == 'application/msword') {
    $extension = ".doc";
}

Regardless of whether the file I upload is .docx or .doc, the statement always evaluates to .doc. Why is docx not being detected? Am I using the wrong mime type?

Same is true for excel files (xlsx, xls)..

链接地址: http://www.djcxy.com/p/7952.html

上一篇: 在使用ng2FileSelect时,doc和docx的确切MIME类型是什么

下一篇: PHP文件上传finfo MIME类型检测不正确?