I'm creating a wordpress meta box and I need to scan a directory of subdirectories containing images within my template and add these to a select dropdown so I can use the filename in my template.
The images are currently arranged in the folder like this:
Parent Folder
|_ Secondary Folder
|_ Image.png
|_ Image.jpg
|_ Image.gif
|_ Secondary Folder
|_ Image.png
|_ Image.jpg
|_ Image.gif
Ideally I'd like to keep that structure in my select dropdown ie.
Secondary Folder .
|_ Image.png
I've been using this:
function get_dir_path(){
return dirname(__FILE__).'/library/images';
}
$largeImagesdir = get_dir_path() . '/960x345/';
if ($dh = opendir($largeImagesdir)) {
while (($file = readdir($dh)) !== false) {
$lfiles .= '<option>' . $file . '</option>';
}
closedir($dh);
}
$buildbox .= '<select>' . $lfiles . '</select>';
However this of course only works if I set the $largeImagesdir var to be one of the sub directories...
Can anyone help?