reenadak

Get File Extension

Feb 20th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1.     /*
  2.     - Get File Extension
  3.     - Gets the file extension from the file's name.
  4.    
  5.     $fileName      - The name of the file to get the extension of.
  6.     $includePeriod - Whether or not to include the prefix period (eg. ".txt")
  7.     */
  8.    
  9.     public function getFileExtension($fileName, $includePeriod = true) {
  10.         if (strpos($fileName, ".")) {
  11.             $sides = explode(".", $fileName);
  12.             $ext = "";
  13.  
  14.             if ($includePeriod)
  15.                 $ext .= ".";
  16.  
  17.             $ext .= $sides[count($sides) - 1];
  18.             return $ext;
  19.         } else
  20.             return "N/A";
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment