Search code snippets, questions, articles...

Get file name form url in PHP

<?php
    $url = "https://remote-url-path/filename.jpg";
    echo basename($url);
?>
Output
filename.jpg

If you want to get file name form a URL or path in PHP you can use basename() function in PHP. It will return the file filename when the URL is passed as a parameter.

Was this helpful?
0 Comments