Hi everyone,
I'm trying to make a script that can go into a specified directory and form an array of all of the sub-directory names within that directory. Here's what I've got:
$albums=array();
$dir='/home/matt/public_html/temp';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
echo "$file";
if (is_dir($file) && ($file != ".") && ($file !=".." ) ) {
array_push($albums,$file);
}
}
closedir($handle);
}
print_r($albums);
When I run this script, I find that all of the files and directories are properly displayed with the echo command (i.e. the readdir command is finding them), but the albums directory is shown as being empty, i.e., none of the subdirectories appear. Is there something wrong with my code that I cannot tell.
Thanks in advance for your help.
Matt