Matthew1980 - 7:46 am on May 14, 2010 (gmt 0)
Hi there camilord,
Are you just trying to get the file extension, so that you can decide if it's 'allowed' or 'not allowed'?
Also is the function getfileextension() your own, I presume so as it's not a predefined function, the nearest is: [uk.php.net ]
The easiest way to get the filetype is this:-
//imagine as the string is filename.jpg
$fileExt = strip_tags(strtolower($_POST['your_file']));//clean and convert to lower case
$ext = strstr($fileExt, ".");
This will echo .jpg - note: it includes the . Ok!
Could shove this into a function:-
Note that if its always from a $_POST or a $_GET you don't need to pass it into a function as it is a superglobal, so by definition the array (if set) is available throughout the scope of your project, ie: accesible anywhere ;)
//for a var
$ext = strstr(strtolower(strip_tags($input)), ".");
//for a $_POST
$ext = strstr(strtolower(strip_tags($_POST['your_file'])), ".");
One last thing, I think that $_POST['file'] may be reserved for doing file uploads($_FILES), but I could be wrong there.