Get File Extention in PHP

function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }
$filename = stripslashes($_FILES['upload']['name']);
         //get the extension of the file in a lower case format
          $extension = getExtension($filename);
         $extension = strtolower($extension);
echo $extension;

Tags: 
X