Basename is a native php function
You can find how to use it in the link. If you want laravel specific helpers look at
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, Is it possible that basename function does not wok correctly i have the following code and it always gives back the full path for me not just only the file name.
$origiimg = ($teams->profileimg);
$new = basename($origiimg);
dd($new );
dd it returns "C:\fakepath\alps.jpg"
then i have tried
$origiimg = "C:\fakepath\alps.jpg";
$new = basename($origiimg);
dd($new );
dd it returns "C:\fakepath\alps.jpg"
Do i miss something here? It should be very simple to get "alps.jpg" as far as I know but no luck for 5hours now.
The problem is you're using windows style paths. If you switch your \'s to /'s it will work.
$origiimg = "C:/fakepath/alps.jpg";
$new = basename($origiimg);
dd($new ); // alps.jpg
basename() only works on /'s.
So if you have those paths hardcoded, like in the db or something (I hope not as they're specific to your OS), you could do something like
$origiimg = str_replace('\\', '/', $teams->profileimg);
$new = basename($origiimg);
dd($new );
It needs 2 \'s for the first part because \ is an escape char.
Please or to participate in this conversation.