I've got an array in which the elements are the filenames of all files in a directory. I then sort the array and echo the list back onto the page as links.
I wanted to sort the array according to how new the files are. I've tried using my code like this
Code: Select all
/*Function to get array of all files in directory*/
function listnew()
{
$ToneArray = array();
/*Specifies the directory files are in*/
$handle = opendir('latest');
/*Loops in directory to find files*/
while ($file = readdir($handle))
{
/*Reads the files without extensions then makes the array*/
$tonefile = substr($file, 0, -4);
$modified = filemtime($file);
$ToneArray[$tonefile] = $modified;
}
return $ToneArray;
}
$ToneArray = listnew();
echo '<div align=left class="scroll" style="overflow:auto; width:300px; height:325px;">';
echo '<p align=center><b><u>Latest Ringtones</u></b>';
echo '<p class="test">';
/*Sort the Array*/
asort ($ToneArray);
$type = "newest";
/*Display Links for all the files*/ /*NB: $type was defined earlier in the script*/
foreach($ToneArray as $n => $v) {
echo '<a href="index.php?location='.$type.'&n='.$n.'">'.$n.'</a><br>';
}
echo '</div>';Is the modified date that you see when you right click and view file properties the same as what the script reads as the modified date or is my code wrong?
These files are not CHMOD to anything other than the standard 0755 but I can't see why this should make a difference.
Thanks