[英]All sub directories with content to array
Okay so I currently have a function to browse to all the directories and show the image on the page(As seen below) 好的,因此我目前具有浏览所有目录并在页面上显示图像的功能(如下所示)
recursiveGlob('wp-content/plugins/myplugin/v1/images/backgrounds', 'jpg', $weburl);
function recursiveGlob($dir, $ext, $weburl) {
$globFiles = glob("$dir/*.$ext");
$globDirs = glob("$dir/*", GLOB_ONLYDIR);
var_dump($globDirs);
foreach ($globDirs as $dir) {
recursiveGlob($dir, $ext);
}
foreach ($globFiles as $file) {
$loc = str_replace('wp-content/plugins/myplugin/v1/', '', $file);
echo '<li class="uploadedimage default-image"><img src="' . $weburl . $loc .'" alt="default-usable-image" /></li>';
}
}
Now I'm wondering how to get the same idea(Get all folders and content(Images only, jpg in this case)) And add these image to an array similar to this: 现在我想知道如何获得相同的想法(获取所有文件夹和内容(在这种情况下,仅包含图片,jpg)并将这些图片添加到类似于以下的数组中:
Array (
[FolderName1] => Array (
[0] => someimage.jpg
[1] => anotherimage.jpg
)
[FolderName2] => Array (
[0] => moreimages.jpg
[1] => muchimages.jpg
)
)
$result_array = array();
foreach($globDirs as $d){
foreach($globFiles as $file){
// Before push files in this array, check whether this file is in this folder or not.
// If that file is in that folder then add it.
if(//your condition...){
array_push($result_array[$d], $file);
}
}
}
print_r($result_array);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.