PHP从子目录获取图像
我以前有下面的代码,用于从特定文件夹获取图像。 现在我想从多个文件夹中获取单个页面上的图像 我的文件夹名为“图像”,而不是在“图像”文件夹中我有folderOne,folderTwo,folderTwo。jpg文件仅在这些子文件夹中 下面是我以前的代码>>>PHP从子目录获取图像,php,scandir,Php,Scandir,我以前有下面的代码,用于从特定文件夹获取图像。 现在我想从多个文件夹中获取单个页面上的图像 我的文件夹名为“图像”,而不是在“图像”文件夹中我有folderOne,folderTwo,folderTwo。jpg文件仅在这些子文件夹中 下面是我以前的代码>>> <?php function scd($dir) {$files = scandir($dir); asort($files); return $files; } $ou
<?php
function scd($dir)
{$files = scandir($dir);
asort($files);
return $files;
}
$output = '<div> ';
$dir = "images";
$files = scd($dir);
foreach($files as $file){
shuffle($files);
if($file==='.' || $file==='...'){continue;}
$output.='<img src="'.$dir.'/'.$file.' " />';
}
echo $output. "</div>";
?>
使用此代码,它只显示“图像”文件夹中的文件,而不从子目录获取文件
请帮助..谢谢您的帮助..!我个人建议您不要使用
scandir()
看一看谢谢你抓住了它,@meda.)
<?php
function scd($path) {
$di = new RecursiveDirectoryIterator($path);
$iterator = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
$files = [];
foreach ($iterator as $file) {
$files[] = $file;
}
asort($files);
return $files;
}