I have a directory loaded with webcam photos, the photo's are named as garage-YYMMDDHHMMSS.png
I call the function as
$Debug = "Off";
$Path_To_Webcam_Images = "webcam/";
$Import_Images_Array = Scan_Image_Directory($Path_To_Webcam_Images,"png",$Debug);
function to scan the directory and load the filenames into an array.
function Scan_Image_Directory($This_Variable,$That_Variable,$Debug) {
$Path_To_Uploaded_Images = $This_Variable ;
$Import_Images_Array = array();
if (is_dir($Path_To_Uploaded_Images)) {
$Opened_Directory = opendir($Path_To_Uploaded_Images);
while ($Current_File = readdir($Opened_Directory)) {
if (is_file($Path_To_Uploaded_Images.$Current_File)) {
$parts = explode(".", $Path_To_Uploaded_Images.$Current_File);
if (is_array($parts) && count($parts) > 1) {
$extension = end($parts);
if (strtolower($extension) == $That_Variable){
$Import_Images_Array[] = $Path_To_Uploaded_Images.$Current_File;
}
}
}
}
closedir($Opened_Directory);
}
return $Import_Images_Array;
}
I then run the following to get them all into a nice date order.
ksort($Import_Images_Array,SORT_STRING);
$Photo_Count = 0;
foreach ($Import_Images_Array as $key => $value) {
$Photo_Count ++;
if ($Photo_Count == 10) { break; }
echo $Photo_Count." Photo:".$value."<br />";
}
Now when I run this on my WAMP I get all the filenames (624 of them) all in an array perfect for working on however when I run the exact same code on my main server I always get a complete jumble of filenames in the array (the contents of the directory are identical on both servers) and running krsort it just reverses the array complete with the jumbled filenames.
I have tried using the sort flags as well, they all work as expected on my WAMP but jumbled on my main. It's as iff ksort was not actually working.
I don't know why this happens and could help with some help.
Thank you
Here are the results of the code on WAMP
1 Photo:webcam/garage-100607180902.png
2 Photo:webcam/garage-100607181128.png
3 Photo:webcam/garage-100608053419.png
4 Photo:webcam/garage-100610103644.png
5 Photo:webcam/garage-100610103858.png
6 Photo:webcam/garage-100610104112.png
7 Photo:webcam/garage-100610104554.png
8 Photo:webcam/garage-100610163445.png
9 Photo:webcam/garage-100610170844.png
10 Photo:webcam/garage-100610171100.png
And here is the results of the code on my main
1 Photo:webcam/garage-100616143011.png
2 Photo:webcam/garage-100612135126.png
3 Photo:webcam/garage-100615153551.png
4 Photo:webcam/garage-100616144345.png
5 Photo:webcam/garage-100613090312.png
6 Photo:webcam/garage-100612131900.png
7 Photo:webcam/garage-100615154007.png
8 Photo:webcam/garage-100616102236.png
9 Photo:webcam/garage-100610171336.png
10 Photo:webcam/garage-100612075052.png