The following script makes it more easy to get the file extension from a file name:
1 2 3 4 5 6 7 8 |
function get_file_extension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } echo get_file_extension('myfile.txt'); |
In case you have the ability to use mime type detection, you could combine it with the above function to validate if the extension is valid for the content of the file.