LanceT Posted March 4, 2007 Share Posted March 4, 2007 I know with images you can use images/jpg but how do you check it with an MP3? sounds/mp3 ? lol. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/41071-checking-if-a-file-is-mp3/ Share on other sites More sharing options...
ted_chou12 Posted March 4, 2007 Share Posted March 4, 2007 checking the extensions would be the basic to it, however, i believe there are some more complicated way to ensure that the uploader listens to mp3, this is the extension checking. <?php $ext = explode(".", $filename) if ($ext[1] == "mp3") {echo "It is a mp3 file";} else {echo "It isnt a mp3 file";} ?> Ted Quote Link to comment https://forums.phpfreaks.com/topic/41071-checking-if-a-file-is-mp3/#findComment-199062 Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 @ted- the problem with your script is that files named this way for an example won't work: file.name.mp3 or file.MP3 Solution: <?php $ext = strtolower(substr(strrchr($filename,"."),1)); if ($ext == "mp3") echo "Mp3"; ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/41071-checking-if-a-file-is-mp3/#findComment-199066 Share on other sites More sharing options...
wildteen88 Posted March 4, 2007 Share Posted March 4, 2007 you can also use substr $filename = 'somefile.mp3'; // check if file has an .mp3 file extension if(substr($filename, -4, 4) == '.mp3') { echo 'Mp3s are not allowed!'; } else { echo 'File is ok!'; } Umm Orio beat me to it Quote Link to comment https://forums.phpfreaks.com/topic/41071-checking-if-a-file-is-mp3/#findComment-199072 Share on other sites More sharing options...
ted_chou12 Posted March 4, 2007 Share Posted March 4, 2007 thanks, i see. Quote Link to comment https://forums.phpfreaks.com/topic/41071-checking-if-a-file-is-mp3/#findComment-199077 Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 Btw, I checked what mime type does php give for mp3 and it's audio/mpeg. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/41071-checking-if-a-file-is-mp3/#findComment-199081 Share on other sites More sharing options...
LanceT Posted March 4, 2007 Author Share Posted March 4, 2007 guys thanks alot. audio/mpeg was just what i needed. Quote Link to comment https://forums.phpfreaks.com/topic/41071-checking-if-a-file-is-mp3/#findComment-199300 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.