Getting mime type from file name in php

后端 未结 2 1209
北恋
北恋 2020-12-09 08:00

I have the following function to produce the mime type from a file name:

    function get_mime_type($file) {
      if (function_exists(\'finfo_open\')) {
            


        
2条回答
  •  执念已碎
    2020-12-09 08:48

    If you check the documentation, you can see that you are not doing anything wrong. But if you do a bit more research:

    https://stackoverflow.com/a/3664655/3784145

    you can see that the mime type you get is correct, but the extension doesn't need to match with the mime type as explained here:

    http://nl3.php.net/manual/en/function.mime-content-type.php#85879

    I would therefore use the files suffix to determine the files mime type. (as seen in the first example)

提交回复
热议问题