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.

Example:

basename("https://www.pakainfo.com/welcome/new-logo-pakainfo.png");

How to get filename without extension in PHP?

Example

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

$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 infinityknow.com 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.