Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mime type not working for MP3

I am having an issue when using mime types in PHP.

As a security feature, I am placing any content uploaded to my server by users in a directory outside of public_html. When a user wants to access their uploaded files in the browser, I use php script to pull the file from the secure folder using readfile and header('content-type'), the issue I am having so far only pertains to mp3s.

When I try and use this for a mp3 file, the file doesn't actually play in the browser, but M4As work fine. And it isn't every mp3 file too, it just seems that when I get the mime-type of some mp3 files php can't tell that they are mp3s. The mp3s also playback fine if I download them, so it isn't an issue with the file per say (unless the file has the wrong mime-type somehow).

How do I get it to tell that they ARE mp3s?

My getFile code is here: codepad.org

Any help would be appreciated greatly, I'll even give you some of my tracking cookies!

like image 378
CJT3 Avatar asked Feb 22 '26 03:02

CJT3


1 Answers

For mp3s, did you try:

header("Content-Type: audio/mpeg");
like image 183
flux Avatar answered Feb 24 '26 15:02

flux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!