Get filename from url in php
Hello Friends. To get filename from the url use this function.
Call function like this
echo get_filename();
function get_filename(){ $php_self = $_SERVER['PHP_SELF']; $filename = explode("/", $php_self); $filename = array_reverse($filename); return $filename[0]; }
Call function like this
echo get_filename();
Get filename from url in php
Reviewed by JS Pixels
on
April 25, 2011
Rating:
Cool, but it’s not working if you have some parameters in the URL!!
ReplyDeleteI tried this:
$filename = basename($url);
$parts=explode("?",$filename);
$filename = $parts[0];
echo $filename;
And it works!!
Thanks for your comments !!
ReplyDeleteBut that code also works. Please try again..