That is not about getting file name from the url of current page. I have a php file like that.
You can also use string functions like strrpos to get the last position of '/' and then use the substr and strlen functions to get the last part of the string.
$fileurl = 'http://example.com/filepath/filepath2/myfile.doc'; $file_name=substr($fileurl,strrpos($fileurl,'/')+1,strlen($fileurl));
echo $file_name;
This should work for you:
<?php
$fileurl = 'http://example.com/filepath/filepath2/myfile.doc';
echo basename($fileurl);
?>
Output:
myfile.doc
Use basename()
function in php to return a file name from the path.Use the code below
<?php
$fileurl = 'http://example.com/filepath/filepath2/myfile.doc';
$file_name=basename($fileurl);
echo $file_name; // Will output myfile.doc
?>
Hope this helps you
Alternatively explode:
<?php
echo end(explode('/','http://localhost/login/uploads/blog_images/woman4.jpg'));
Output:
woman4.jpg