PHP: Getting File extension and file basename

Here is a script for getting file extension. It will take care of the file name like this: yourfilename.inc.php etc and not only filename.inc or fileename.php. It will get your last part of file irrespective of how many dots in file.

<?php
// will get the file name out of whole path (path/to/file.inc.php)
$filename = basename($filePath);
// split it into part by dot
$filePartArr = explode('.', $f);
// get the last one
$ext = $arr[count($filePartArr) - 1];
?>

Here if you want to get filename without extension

<?php
// just use the php function basename and provide the extension with dot
$fileBaseName = basename ($file, '.php');
?>
Comments are open for an year period. Please, write here on Facebook page.