How to get filename without extension in PHP

How to get filename without extension in PHP

In this post, you will know how to get filename without extension from given file path in PHP.

You will just need to use very simple PHP pre-defined methods to get filename.

  1. $imagePath = "{file-path}/filename.png";
  2. $ext = pathinfo($imagePath, PATHINFO_EXTENSION);
  3. $file = basename($imagePath,".".$ext);
  4. print_r($file);

In above example file-path will be path of your selected file.

pathinfo method is used to get information about path.

PATHINFO_EXTENSION is used to get extension of file if there are more than one extension with given path then it will return last one only.

basename is used to get filename without extension. In basename method, second parameter suffix specifies a extension that is optional but if you need to get only filename then you will have to pass extension as second argument in this method.

Phone: (+91) 8800417876
Noida, 201301
Attention Required! | Cloudflare

Sorry, you have been blocked

You are unable to access ressim.net

Why have I been blocked?

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.