Forum Moderators: coopster
array scandir [php.net] ( string directory [, int sorting_order [, resource context]] )
Note, the array will contain filenames as well as directory names. You would still need to test each entry to confirm it actually is a file.
<?
$path = '../images/temp/';
# Initialise list arrays, files and array counters for them
$f = 0;
$images_arr = array();
if (@$handle = opendir($path)) {
while (false!== ($file = readdir($handle))) {
if($file!= "." && $file!= ".." && $file[0]!= ".") {
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) $nr_images++;
$images_arr_ftime[$f++] = filemtime($file); //<---- here it is, just a seperate array to store filetimes
$images_arr[$f++] = $file;
};
};
closedir($handle);
};
asort( $images_arr ); reset( $images_arr );
asort( $images_arr_ftime ); reset( $images_arr_ftime );
//test
for ($i=0; $i<$nr_images; $i++){
echo 'filename: '$images_arr[$i].' filetime: '.$images_arr_ftime[$i];
}
?>
<?
//phpinfo()
$path = 'images';
# Initialise list arrays, files and array counters for them
$t = 0;
$f = 0;
$images_arr['name'] = array();
$images_arr['time'] = array();
if (@$handle = opendir($path)) {
while (false!== ($file = readdir($handle))) {
if($file!= "." && $file!= "..") {
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)){
$images_arr['time'][$t++] = filemtime($file); //<---- here it is, just a seperate key in the array to store filetimes
$images_arr['name'][$f++] = $file;
};
};
};
closedir($handle);
asort( $images_arr['time'] );
asort( $images_arr['name'] );
}//test
foreach ($images_arr['time'] as $key=>$ftime){
$fname = $images_arr['name'][$key];
echo '<strong>filename:</strong> '.$fname.' <strong>filetime:</strong> '.$ftime.'<br/>';
}?>