Porl123 Posted April 26, 2009 Share Posted April 26, 2009 is it possible to read the extension of an audio file without using substr()? I'm trying not to use that seeing though it can have problems in some areas. if anyone can point me to some functions or knows any methods i'd be greatful, thanks people! Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/ Share on other sites More sharing options...
.josh Posted April 26, 2009 Share Posted April 26, 2009 what's wrong with using substr? anyways...you could always explode at the dot and look at the 2nd element of the returned array Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/#findComment-819912 Share on other sites More sharing options...
premiso Posted April 26, 2009 Share Posted April 26, 2009 Another route: pathinfo with the 2nd parameter (if your version supports it) of PATHINFO_EXTENSION Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/#findComment-819913 Share on other sites More sharing options...
Porl123 Posted April 26, 2009 Author Share Posted April 26, 2009 Ah that's the problem, it's an external link Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/#findComment-819914 Share on other sites More sharing options...
coalgames Posted April 26, 2009 Share Posted April 26, 2009 I dont get why you dont want to use substr() function. You could use regular expressions to get extension of the file. But, if you dont want to use substr() here is a way to do it $filename = 'something.wav'; $fl = strlen($filename); // File length $fileextension = $filename[$fl] . $filename[($fl-1)] . $filename[($fl-2)]; if ( $fileextension == 'wav' ) { echo 'Valid file extension'; } The downside to this is that the person could just change the extension of the file with a malicious exe inside. Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/#findComment-819915 Share on other sites More sharing options...
.josh Posted April 26, 2009 Share Posted April 26, 2009 I dont get why you dont want to use substr() function. You could use regular expressions to get extension of the file. But, if you dont want to use substr() here is a way to do it $filename = 'something.wav'; $fl = strlen($filename); // File length $fileextension = $filename[$fl] . $filename[($fl-1)] . $filename[($fl-2)]; if ( $fileextension == 'wav' ) { echo 'Valid file extension'; } The downside to this is that the person could just change the extension of the file with a malicious exe inside. I don't know why on earth someone would choose that over substr but regardless, you made a small fubar in judgement. strlen returns length of string but elements start at 0 not 1 so it would be $fl-1,$fl-2,$fl-3 not $fl,$f-1,$fl-2 Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/#findComment-819917 Share on other sites More sharing options...
coalgames Posted April 26, 2009 Share Posted April 26, 2009 Oh ok thanks for the correction. Yeah, substr is way easier. substr((strlen($file))-1,-0); But I think pathinfo is the easiest. Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/#findComment-819920 Share on other sites More sharing options...
.josh Posted April 26, 2009 Share Posted April 26, 2009 lol umm you fubared your math again...and besides that, you're over-complicating it... substr($file,-3); Quote Link to comment https://forums.phpfreaks.com/topic/155762-verifying-music-link-extensions/#findComment-819922 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.