MIME error when uploading with PHP

A website I am building allows file uploads by authorised users. For any specific category of uploads, a set of file types is allowed, eg .pdf and .docx, so that my client can choose what they want to accept.

When uploading, I check the uploaded file's MIME type (using finfo_open(FILEINFO_MIME_TYPE) ) against a database table of MIME types for that extension.

In testing, I am uploading a docx file from my PC - it has a docx extension and Windows reports the file type as application/vnd.openxmlformats-officedocument.wordprocessingml.document which is what I expect. However, finfo_open is giving me a MIME type of application/msword.

Does finfo_open's information come from within the file or from something in the browser or the upload process (in which case I guess I'll need to specify additional MIME types allowed) or is it something within the web server (in which case, can it be modified with php.ini)?


I believe in PHP it's safer to use the $_FILES to check out to file MIME type.

Still, I don't think it bothers for this. Are you sure you gave a docx and not just a doc document? Usually application/msword is the mime type for doc file extension... Make sure that you save your file using the right version of microsoft word and in the right format and then try again. Also, I'd try to use a print_r on $_FILES to see if what it tells you about the file? Does it tells you that the file has a different mime type?

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

上一篇: 防止上传.sh文件到服务器uisng php

下一篇: 使用PHP上传时出现MIME错误