I'm seeking to change a download counter script: http://www.phpkode.com/source/s/dscript-php-file-download-counter/dscript-php-file-download-counter/Includes/functions.php so that it sorts by descending date order of filename as seen by the server instead of sorting in descending alphanumeric order of filename as now. The script counts downloads for files stored on a server, saves the download counts in a log file, then using an array built from the log file, outputs the download count for each file to a web page. This is the function I believe needs to change
// Function to read the log file, and return an array as (filename => downloads)
function read_log()
{
global $path;
// Declare Array for holding data read from log file
$name = array(); // array for file name
$count = array(); // array for file count
$file = @file("$path/Includes/log");
if(empty($file))
{
return null;
}
// Read the entire contents of the log file into the arrays
$file = fopen("$path/Includes/log","r");
while ($data = fscanf($file,"%[ -~]\t%d\n"))
{
list ($temp1, $temp2) = $data;
array_push($name,$temp1);
array_push($count,$temp2);
}
fclose($file);
// $file_list contains data read from the log file as an array (filename => count)
$file_list=@array_combine($name,$count);
ksort($file_list); // Sorting it in alphabetical order of key
return $file_list;
}
The log file syntax is file name then a TAB then download count (0 or higher). New files are added frequently which the script has to count. I need the latest added file to be at the top of the web page but I now need to change the file names of new files which causes them not to come to the top of the list if sorted as now. I looked at these http://stackoverflow.com/questions/16733128/sort-array-by-date-in-descending-order-by-date-in-php http://stackoverflow.com/questions/6401714/php-order-array-by-date https://stackoverflow.com/questions/3302900/how-to-sort-output-from-several-log-files-by-date but I don't get a specific enough idea of what I must change in the script above the lines where ksort is invoked.