How to Get File Name without Extension in PHP?

By Hardik Savani November 5, 2023 Category : PHP


This simple article demonstrates of get image name without extension php. This post will give you a simple example of php remove file extension from path. I explained simply about how to get filename in php without its extension. I explained simply step by step get image name without extension php.

If you need to get only the filename from a URL without the file extension, you can achieve this by using the basename() PHP function. In the example below, I will demonstrate how to obtain the image name without the extension. Firstly, we need to identify the extension of the given filename URL, and then we can use basename() to remove that extension, as demonstrated below:



$imagePath = "/home/hd/html/imagefilename.jpg";

$ext = pathinfo($imagePath, PATHINFO_EXTENSION);

$file = basename($imagePath,".".$ext);





I hope it can help you...

Tags :