在Laravel 5中仅获取文件名

jur*_*urh 5 filenames path laravel

当我有一个像这样的变量时:

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

$files = File::allFiles($storagePath);

return View::make('documentatie.overzicht') ->with('files', $files); 
Run Code Online (Sandbox Code Playgroud)

在我看来,文件显示为:

/xampp/htdocs/systeembeheer/public/download/test.txt但是我只想看test.txt

KuK*_*KeC 10

您必须使用basename,它返回路径的结尾名称部分。

所以在您看来,使用类似

//$file is full path 
echo basename($file);
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢,它适用于 larave 8 和 php 8 (2认同)