Getting only the filename in laravel 5

15,233

You have to use basename which returns trailing name component of path.

So in your view use something like

//$file is full path 
echo basename($file);
Share:
15,233
jurh
Author by

jurh

Updated on June 25, 2022

Comments

  • jurh
    jurh almost 2 years

    When i have a variable like:

    $storagePath = ('/xampp/htdocs/systeembeheer/public/download');

    $files = File::allFiles($storagePath);
    
    return View::make('documentatie.overzicht') ->with('files', $files); 
    

    In my view, the files displayed as:

    /xampp/htdocs/systeembeheer/public/download/test.txt, but I want to see only test.txt.

  • Ivandez
    Ivandez about 3 years
    thanks a lot, it works with larave 8 and php 8