【问题标题】:Getting only the filename in laravel 5仅获取 laravel 5 中的文件名
【发布时间】:2016-11-17 04:11:26
【问题描述】:

当我有一个变量时:

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

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

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

在我看来,文件显示为:

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

【问题讨论】:

  • 你试过echo basename($file);吗?
  • 非常感谢!我做了: 在我的视图文件中,它现在可以工作了!
  • 没问题,我已经写了我的解决方案作为答案。随意接受它:)

标签: laravel path filenames


【解决方案1】:

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

所以在你看来使用类似

的东西
//$file is full path 
echo basename($file);

【讨论】:

  • 非常感谢,它适用于 larave 8 和 php 8
猜你喜欢
  • 2015-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多