Raf*_*ngh 0 directory image file laravel
我目前正在使用以下功能:
public function recentImages(){
foreach(\File::allFiles("up") as $path){
$files[] = pathinfo($path);
}
return view('recent-images-view')->with('files',$files);
}
Run Code Online (Sandbox Code Playgroud)
要列出我上传文件夹中的所有图像,但这还包括在名为“thumbs”的单独文件夹中分隔的缩略图。
我想知道是否有任何方法可以告诉 allFiles 函数排除名称为拇指的文件夹。或者我应该完全不同地处理这个?
感谢您提前提供任何信息。
File::allFiles()
将递归地从给定目录中获取所有文件。尝试使用File::files()
which 将仅从给定目录中获取所有文件。
更新
由于您有其他需要的目录。我想出了以下解决方案。
public function images(){
foreach(\File::directories('up') as $dir) { // Get all the directories
if(str_contains('thumbs', $dir)) { // Ignore thumbs directory
continue;
}
foreach(\File::files($dir) as $path) { // Get all the files in each directory
$files[] = pathinfo($path);
}
}
return view('recent-images-view')->with('files',$files);
}
Run Code Online (Sandbox Code Playgroud)
没有测试它,这个概念是通过忽略不需要的目录来获取所有目录并获取这些目录中的所有文件。