php - 如何从 laravel 5.5 的存储内部文件夹中获取文件?
问题描述
我需要从 storage->app->public->huetten-> 列出文件,它包含 17 个文件夹。每个文件夹都包含图像。任何帮助,将不胜感激。
public function show($id)
{
if(!empty($id)) {
$directories = Storage::disk('public')->allDirectories('huetten');
foreach ($directories as $directory) {
//dd($directory); // Here i get huetten/folder1
$files = Storage::files($directory);
foreach ($files as $file) {
dd($file); // But here files are not listing
}
}
}
}
解决方案
存储使用默认的文件系统磁盘,在新的 Laravel 项目中config/filesystems.php
设置为local
( ie )。 storage/app/
我假设它在您的项目中设置为相同的值。
您想列出 storage/app/public 中的文件,这对应于config/filesystems.php
.
在您的循环中,您可以通过获取一个用于公共磁盘的 Filesystem 实例来正确搜索目录,就像您在列出目录时所做的那样。
$files = Storage::disk('public')->files($directory);
/* [ 'storage/app/public/huetten/folder1/foo', 'storage/app/public/huetten/folder1/bar', ...] */
推荐阅读
- c# - 通过反射在脚本组件中组装适用于随机情况
- java - 如何在Android中从url显示授权的pdf而不下载它?
- python-3.x - python中的多处理问题[OSError:[WinError 6]无效的驱动程序]
- c# - 在 EnumDropDownListFor / ListBoxFor 上绑定多个值
- ios - Amazon iOS 应用程序如何实时搜索产品?
- sql-server - AWS DMS 复制实例无法连接本地机器 SQL Server 测试端点
- javascript - console.log returning undefined in for loop
- oracle - Spark Scala计数功能没有响应
- java - Tomcat 7 - 忽略数据库连接池参数 (DBCP)
- c++ - Optimizing OpenGL rendering