Array'et $files var selvfølgelig tomt i det oprindelige script, så ved at gøre brug af det lykkedes at få filerne sorteret :-)
<?
Header("content-type: application/x-javascript");
$pathstring=pathinfo($_SERVER['PHP_SELF']);
$locationstring="
http://" . $_SERVER['HTTP_HOST'].$pathstring['dirname'] . "/";
function returnimages($dirname=".") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$files[$curimage]=$file;
$curimage++;
}
}
closedir($handle);
}
array_multisort($files, SORT_DESC);
for($i = 0;$i < sizeof($files); $i++) {
echo 'picsarray[' . $i .']="'. $files[$i] .'";';
}
return($files);
}
echo 'var locationstring="' . $locationstring . '";';
echo 'var picsarray=new Array();';
returnimages()
?>