Krash Posted March 7, 2010 Share Posted March 7, 2010 Trying to restrict file uploads to mp3 files only using this - if ($uploaded_type != "audio/mpeg") { echo "You may only upload mp3 files.<br><br>"; $ok=0; } It does not recognize mp3s, and will not allow any file types. It works for other types (i.e., text/html). What am I doing wrong? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/194435-upload-file-restrictions/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2010 Share Posted March 7, 2010 Echo the value in $uploaded_type when your validation test fails so that you can see what exactly it is. Different browsers send different mime types for the same file and your code must allow for multiple values. Quote Link to comment https://forums.phpfreaks.com/topic/194435-upload-file-restrictions/#findComment-1022716 Share on other sites More sharing options...
Krash Posted March 7, 2010 Author Share Posted March 7, 2010 OK - type = audio/x-mpeg (that's in IE). How many different types are commonly used? Is there a listing of them anywhere? The only one I could find just showed audio/mpeg. Quote Link to comment https://forums.phpfreaks.com/topic/194435-upload-file-restrictions/#findComment-1022732 Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2010 Share Posted March 7, 2010 Unfortunately, there is a gap between the actual defined and registered mime types (which were originally defined for SMTP email) http://www.iana.org/assignments/media-types/ and what each browser does (for example the x- types are non-standard and are not registered.) http://en.wikipedia.org/wiki/Internet_media_type Best bet is to test actual files in the target browsers. Quote Link to comment https://forums.phpfreaks.com/topic/194435-upload-file-restrictions/#findComment-1022740 Share on other sites More sharing options...
Krash Posted March 8, 2010 Author Share Posted March 8, 2010 OK -got it working for mpeg and x-mpeg. I'll add others as they come up. Thx for the assist. Quote Link to comment https://forums.phpfreaks.com/topic/194435-upload-file-restrictions/#findComment-1022837 Share on other sites More sharing options...
Andy-H Posted March 8, 2010 Share Posted March 8, 2010 $filetype = explode("/", $uploaded_type); if ( stristr($filetype[0], "audio") === false && stristr($filetype[1], "mpeg") === false && stristr($filetype[1], "mpa") === false) { echo "You may only upload mp3 files.<br ><br >"; $ok=0; } You could try that? //EDIT Added MPA check after reading wikipedia link. Quote Link to comment https://forums.phpfreaks.com/topic/194435-upload-file-restrictions/#findComment-1022844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.