Finding Extensions in PHP without Reading the Mime Type

For all you geeks, finding an extension, cross platform, because application/type doesn’t always work with $_FILES['file']['type'] cross platform.

The mime information is read differently, I ran into this problem on unix when somebody uploaded a pdf edited on a windows machine.

function findExt($f) {
$var = $f;
$explode = explode('.', $var);
$num = count($explode);
$ext = strtolower($explode[$num - 1]);
return $ext;

return substr(strrchr($f, '.'), 1);
}

Then call it as;

if(in_array(findExt($file), $acceptedArray)) {
// Do Something
} else {
// Do something else
}

Tags: , , , ,

Saturday, December 12th, 2009 linux, PHP

Leave a Reply

You must be logged in to post a comment.

FatCloud by Netlife

Powered by My Foursquare