Getting mime type from file name in php

后端 未结 2 1200
北恋
北恋 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:46

    I was trying to get mimeType of file using mime_content_type() and get_mime_type() but it was not working.

    Here this works for me

    $file = $request->file('FILE_NAME_IN_REQUEST');
    $mimeType = $file->getClientmimeType();
    
    0 讨论(0)
  • 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)

    0 讨论(0)
提交回复
热议问题