Php get file name without extention from file path

Php get file name without extention from file path

In ths article, i will let you know php get file name without extension from given file path. There can be multiple methods to get file name. We can manipulate or take out substring from the given string which is basically a full file path.

Here we will use simple php method to get file name without extension in php. Let us understand with an example as given below.

$image_file_path = "{file-path}/filename.jpg";
$ext = pathinfo($image_file_path, PATHINFO_EXTENSION);
$file = basename($imagePath,".".$ext);
print_r($file);

Here, in this example we have taken an image file with full path and used pathinfo() function to get file extension. If there are more than one extension of the file then it will return last extension given in the file.

After that we have used basename() function to get file name without its extensionand in this method we have paased extension that is an option parameter to get only file name.

You can also read the article to enable rewrite mode in apache by clicking on the link below.

Enable rewrite module in Xampp, Wamp, Lamp and apache