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: etc and not only or fileename.php. It will get your last part of file irrespective of how many dots in file.

// will get the file name out of whole path (path/to/
$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

// 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.