简体   繁体   中英

Incorrect mime-type from PHP

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?

I am running the following:

  • Ubuntu
  • PHP 5.2
  • Apache 2

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.

Make sure the Apache MIME types file has the correct MIME type for that file extention. You'll want to look at /conf/mime.types and add these lines if they don't exist.

application/vnd.powerpoint ppt
application/vnd.powerpoint pptx

You will need to restart Apache after making these changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM