Posted inLaravel / php

get filename from url php – How to get filename from path in PHP?

get filename from url php using pathinfo($fullpathimg, PATHINFO_EXTENSION), basename() function and basename($_SERVER[‘REQUEST_URI’], ‘?’ . $_SERVER[‘QUERY_STRING’]) Examples.

get filename from url php

Given full path, find file name in the path. The basename() function returns the filename from a path.

Get file name form url in PHP

To get the file name from a URL in PHP, you can use the basename() function. Here’s an example:

$url = '';
$filename = basename($url);

echo $filename; // Outputs "image.jpg"

In this example, the basename() function takes the URL as an argument and returns the file name from the URL. The file name is then stored in the $filename variable and displayed using the echo statement.


How to get filename without extension in PHP?


$fullpathimg = "{file-path}/new-logo-pakainfo.png";
$ext = pathinfo($fullpathimg, PATHINFO_EXTENSION);
$file = basename($fullpathimg,".".$ext);
$ext = pathinfo($fullpathimg, PATHINFO_EXTENSION);

Get only filename from url in php without any variable values which exist in the url

echo basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);

Don’t Miss : How To Get The Current Page Name Using PHP?

I hope you get an idea about get filename from url php.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype