igs*_*013 31
您可以为Storage类创建另一个磁盘.在我看来,这对你来说是最好的解决方案.
在disks阵列的config/filesystems.php中添加所需的文件夹.该市民在这种情况下的文件夹.
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path().'/app',
],
'public' => [
'driver' => 'local',
'root' => public_path(),
],
's3' => '....'
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用Storage类以下列方式在公用文件夹中工作:
$exists = Storage::disk('public')->exists('file.jpg');
Run Code Online (Sandbox Code Playgroud)
在$如果存在变量会告诉你file.jpg内部存在的公共文件夹,因为在存储磁盘"公众"指向项目的公共文件夹中.
您可以使用自定义磁盘的文档中的所有会话方法.只需添加磁盘("公共")部分即可.
Storage::disk('public')-> // any method you want from
Run Code Online (Sandbox Code Playgroud)
http://laravel.com/docs/5.0/filesystem#basic-usage
Tar*_*dam 21
Storage::disk('local')->files('optional_dir_name');
要么
array_filter(Storage::disk('local')->files(), function ($item) {return strpos($item, 'png');});
请注意,laravel磁盘有files()和allfiles(). allfiles是递归的.
drm*_*ous 14
考虑使用glob.无需在Laravel 5中使用帮助程序类/方法使准系统PHP过度复杂化.
<?php
foreach (glob("/location/for/public/images/*.png") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
?>
Run Code Online (Sandbox Code Playgroud)
您可以使用FilesystemReader::listContents
Storage::disk('public')->listContents();
Run Code Online (Sandbox Code Playgroud)
响应样本...
[
[
"type" => "file",
"path" => ".gitignore",
"timestamp" => 1600098847,
"size" => 27,
"dirname" => "",
"basename" => ".gitignore",
"extension" => "gitignore",
"filename" => "",
],
[
"type" => "dir",
"path" => "avatars",
"timestamp" => 1600187489,
"dirname" => "",
"basename" => "avatars",
"filename" => "avatars",
]
]
Run Code Online (Sandbox Code Playgroud)
小智 7
使用File命名空间来获取公共路径。然后使用此代码从所选目录中获取所有文件。
use File;
Run Code Online (Sandbox Code Playgroud)
例如公共目录名称是“media”
$mediaPath = public_path('media');
$filesInFolder = File::allFiles($mediaPath);
$allMedia = [];
foreach ($filesInFolder as $path) {
$files = pathinfo($path);
$allMedia[] = $files['basename'];
}
Run Code Online (Sandbox Code Playgroud)
要列出目录中的所有文件,请使用此
$dir_path = public_path() . '/dirname';
$dir = new DirectoryIterator($dir_path);
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
}
else {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43578 次 |
| 最近记录: |