How to Get Filename from Path in PHP?

By Hardik Savani May 14, 2024 Category : PHP

Hello Folks,

Today, php get filename from url is our main topic. This example will help you php get image filename from url. This article will give you a simple example of php url basename. let’s discuss about get image name from url php.

Sometimes, we may require to get only filename or image name from full path or url in your PHP project or any framwwork project at that time you can get file name using php pre-define function basename.

If you ever use this function then you can see as bellow example how it's works. I have one image url like, i want to just get image name then you can get image name like this way :

index.php

<?php

$name = basename("https://itsolutionstuff.com/upload/Laravel-5-Mailgun.png");

echo $name;

?>

Output:

Laravel-5-Mailgun.png

I hope it can help you...

Tags :
Shares