Warptweet Posted April 28, 2007 Share Posted April 28, 2007 I use this to check my files type... $fileextension = $_FILES['file']['type']; But it returns the files MIME type, such as image/x-png. How can I get it to check the files actual extension? Such as .mp3 and .zip etc. Link to comment https://forums.phpfreaks.com/topic/49045-check-file-type/ Share on other sites More sharing options...
steelmanronald06 Posted April 28, 2007 Share Posted April 28, 2007 you could always use $_SERVER['PHP_SELF'] and have use PHP to explode the string at the (.) right before the file extension so if you have file.mp3 it would explode at the decimal and you could then echo out the mp3 part. :-\ Link to comment https://forums.phpfreaks.com/topic/49045-check-file-type/#findComment-240308 Share on other sites More sharing options...
Warptweet Posted April 28, 2007 Author Share Posted April 28, 2007 Sorry, but how would I explode the string? I already have the name of the file as the variable $filesname, such as imagename.gif or something, how would I explode the string to get the stuff after the . ? Link to comment https://forums.phpfreaks.com/topic/49045-check-file-type/#findComment-240641 Share on other sites More sharing options...
AndyB Posted April 28, 2007 Share Posted April 28, 2007 Assuming the filename only has one dot ... $bits = explode(".", $filename); $file_ext = $bits[1]; // the second element Link to comment https://forums.phpfreaks.com/topic/49045-check-file-type/#findComment-240654 Share on other sites More sharing options...
steelmanronald06 Posted April 29, 2007 Share Posted April 29, 2007 yea. What AndyB said. If it has more than one dot PHP is easily capable of exploding at the first dot. It just takes a bit of code tweaking. I would tell you how, but I feel people learn a lot more if they make an attempt, even if the attempt fails. Take the code AndyB gave ya, and if you feel like there might be more than one dot in the file name/extension, which normally it is good pratice never to put dots in your filenames, then it is extremely easy to tweak it a bit to fit your needs. Hope it works out for ya. Link to comment https://forums.phpfreaks.com/topic/49045-check-file-type/#findComment-240875 Share on other sites More sharing options...
Warptweet Posted April 29, 2007 Author Share Posted April 29, 2007 I attempted AndyB's code, but it didn't work for some reason. I tried tweaking by changing variable names and switching things, but nothing worked. Are you sure that is how you explode a string and get what is after the .? Link to comment https://forums.phpfreaks.com/topic/49045-check-file-type/#findComment-240881 Share on other sites More sharing options...
steelmanronald06 Posted April 29, 2007 Share Posted April 29, 2007 Yeah, fairly sure. I've looked it over and checked the manual: http://us.php.net/explode Link to comment https://forums.phpfreaks.com/topic/49045-check-file-type/#findComment-240888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.