My code will go through each directory and subdirectory and put the name of each .jpg file into an array.
The script works fine, actually, except for one thing:
As it goes through DIRECTORY#1, it puts all the .jpg files into one array, then it goes through DIRECTORY #2 and puts all those .jpg files into another array, etc. etc.
I'm trying to get ALL .jpg files from ALL subdirectories into ONE array (so that I can sort them by date and find the three newest files - - haven't started on that part of the code yet).
Am I missing something here?
==============
CODE
<?php
$fileList=array();
$folder="/home/barbara/www";
function get_extension($name)
{
$array = explode(".", $name);
$retval = strtolower(array_pop($array));
return $retval;
}
function recursedir($folder)
{
$handle=opendir($folder);
while($file=readdir($handle))
{
if ($file=='.' || $file=='..') continue;
$completepath="$folder/$file";
if (is_dir($completepath) && ($file!=='images') && ($file!=='thumbs'))
{
its a dir, recurse.
recursedir($folder.'/'.$file);
//print "DIR: $folder/$file<br>\n";
//print "<b>DIR: $folder <BR><BR></b>";
}
if (is_file("$completepath"))
{
// IF ENTRY IS A JPG, ADD IT TO THE ARRAY
if (get_extension($completepath)=="jpg")
{
$flastmod = filemtime($completepath);
$llastmod = date("m/d/Y", $flastmod);
$fileList[] = "$llastmod,$completepath";
//if (!is_array($fileList) ) $fileList= array();
//array_push($fileList, $completepath);
//# its a file.
//print "$flastmd " . " " . "$completepath<br>\n";
}
}
}
closedir($handle);
ksort($fileList);
reset($fileList);
//print_r($fileList);
for($i=0; $i<sizeof($fileList); $i++)
{
$holder = explode(",",$fileList[$i]);
echo $holder[0] . " ";
echo $holder[1] . "<BR>";
}
}
recursedir($folder);
clearstatcache;
?>