I was puzzled at first why my files weren't uploading for some users and I found out it was everyone who wasn't using chrome which was the browser I was testing.
Basically I'm doing a file check to make sure they are only able to upload mp3s.
This this was working for chrome, but not firefox.
if ($_FILES['uploaded']['type']=="audio/mp3")
This was working for firefox, but not chrome.
$_FILES['uploaded']['type']=="audio/mpeg"
Could anyone explain why this is happening? I would think both browsers would be able to understand either or... Are there any other browsers I might need to worry about touchy mime types like these?
Edit: If what Pekka suggested is true, what would be the best way to check for a certain mime type?
During the ObjectType step in the request handling process, the server determines the MIME type attributes of the resource requested by the client. Several different server application functions (SAFs) can be used to determine the MIME type, but the most commonly used one is type-by-extension.
According to w3schools, audio/mpeg
is the correct type. But it doesn't matter, MIME types can vary, you absolutely can't rely on them when checking files. Inconsistencies are the rule, and to be expected.
To identify a MP3 file, maybe the getid3 package can help you:
getID3() is a PHP script that extracts useful information from MP3s & other multimedia file formats.
Edit: IANA has an official list of MIME types here. There is no mention of mp3 there, so this is buggy behaviour on Chrome's part.
Edit 2: Your best bet on server side to determine the MIME type of a file is the finfo extension. It tries to determine the type of a file by "content sniffing", looking for specific characteristics of certain file types in the first few bytes of the data. In this process, MIME types can also vary, but at least they are consistent on the same server, so you won't have browser issues any more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With