why some mp3s on mime_content_type return application/octet-stream

后端 未结 3 1131
北海茫月
北海茫月 2020-12-17 23:48

Why is it that on some mp3s files, when I call mime_content_type($mp3_file_path) it returns application/octet-stream?

This is my code:

if (!empty($_FIL         


        
3条回答
  •  萌比男神i
    2020-12-17 23:58

    application/octet-stream is probably mime_content_type s fallback type when it fails to recognize a file.

    The MP3 in that case is either not a real MP3 file, or - more likely - the file is a real MP3 file, but does not contain the "magic bytes" the PHP function uses to recognize the format - maybe because it's a different sub-format or has a variable bitrate or whatever.

    You could try whether getid3 gives you better results. I've never worked with it but it looks like a pretty healthy library to get lots of information out of multimedia files.

    If you have access to PHP's configuration, you may also be able to change the mime.magic file PHP uses, although I have no idea whether a better file exists that is able to detect your MP3s. (The mime.magic file is the file containing all the byte sequences that mime_content_type uses to recognize certain file types.)

提交回复
热议问题