Joh*_*oca 1 php storage laravel laravel-5
如何在laravel Storage中没有特定扩展名的名称查找文件?
像这样 "filename.*"
Storage::get("filename.*")
Run Code Online (Sandbox Code Playgroud)
我试过这个,但似乎没有用.它搜索具有特定扩展名的特定文件.
Storage :: get()将文件路径作为参数,并返回由此路径标识的单个文件的内容,如果找不到file,则抛出FileNotFoundException.
路径中不支持通配符- 原因之一可能是可能存在多个与通配符路径匹配的文件,这会破坏从Storage :: get()返回单个文件内容的规则.扫描整个文件夹也会慢得多,特别是对于远程存储.
但是,您可以使用Storage facade提供的其他功能获得所需内容.首先,列出存储的内容 - 这将为您提供所有可用文件的列表.然后自己过滤列表以获取匹配文件列表.
// list all filenames in given path
$allFiles = Storage::files('');
// filter the ones that match the filename.*
$matchingFiles = preg_grep('/^filename\./', $allFiles);
// iterate through files and echo their content
foreach ($matchingFiles as $path) {
echo Storage::get($path);
}
Run Code Online (Sandbox Code Playgroud)
接受的解决方案有效。不过我发现了另一个并且我更喜欢它:
$matchingFiles = \Illuminate\Support\Facades\File::glob("{$path}/*.log");
Run Code Online (Sandbox Code Playgroud)
请参阅此处的参考: http ://laravel-recipes.com/recipes/143/finding-files-matching-a-pattern
| 归档时间: |
|
| 查看次数: |
6961 次 |
| 最近记录: |