Search multiple folders to load images

I trying to use this code to upload multipal images into one

I only want to upload a specific file ‘thumb.jpg’ that is located in many different folders.

how can I navigate to multipal folders (ie, profile/X/thumb.jpg) while keeping the upload in a random order?

here is the code im working off:

[php]

$dir = ‘images’;
$file_display = array (‘jpg’);
if (file_exists($dir) == false) {
echo ‘Directory ‘’, $dir, ‘’ not found’;
} else {
$dir_contents = scandir($dir);
shuffle($dir_contents);
foreach ($dir_contents as $file) {
$file_type = strtolower(end(explode(’.’, $file)));
if ($file !== ‘.’ && $file !== ‘…’ && in_array($file_type, $file_display) == true) {

echo ‘', $file, '’;
}
}
}

[/php]

thanks for your help.

Don’t have time to test. Maybe this will help

[php]
$path = ‘images’;
$objs = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objs as $obj) {
$extension = pathinfo($obj->getPathname(), PATHINFO_EXTENSION);
if (!$obj->isFile() || !in_array($extension, array(‘jpg’))) {
continue;
}
echo $obj->getPathname() . PHP_EOL;
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service