仅获取 Laravel 5 中的文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38370878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:09:28  来源:igfitidea点击:

Getting only the filename in laravel 5

laravelpathfilenames

提问by jurh

When i have a variable like:

当我有一个变量时:

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

$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.

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

回答by KuKeC

You have to use basenamewhich returns trailing name component of path.

您必须使用basename返回路径的尾随名称组件。

So in your view use something like

所以在你看来,使用类似的东西

//$file is full path 
echo basename($file);