pathinfo is what you're looking for 
PHP.net
$file_parts = pathinfo($filename);
switch($file_parts['extension'])
{
    case "jpg":
    break;
    case "exe":
    break;
    case "": // Handle file extension for files ending in '.'
    case NULL: // Handle no file extension
    break;
}
    $info = pathinfo($pathtofile);
if ($info["extension"] == "jpg") { .... }
    For php 5.3+ you can use the SplFileInfo() class 
$spl = new SplFileInfo($filename); 
print_r($spl->getExtension()); //gives extension 
Also since you are checking extension for file uploads, I highly recommend using the mime type instead..
For php 5.3+ use the finfo class
$finfo = new finfo(FILEINFO_MIME);
print_r($finfo->buffer(file_get_contents($file name)); 
    $file_parts = pathinfo($filename);
$file_parts['extension'];
$cool_extensions = Array('jpg','png');
if (in_array($file_parts['extension'], $cool_extensions)){
    FUNCTION1
} else {
    FUNCTION2
}
    $path = 'image.jpg';
echo substr(strrchr($path, "."), 1); //jpg
    
                If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With