
Originally Posted by
freedomd
LOVE the mod of this script to pull images from folder. I can not figure out what change to make in order to have the images rotate in alpha/numeric order. Please advise! Thanks!!!
Replace:
PHP Code:
<?
function returnimages($dirname="./images/") {
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
echo 'slides[' . $curimage .']=["' . $dirname . $file . '", "", ""];' . "\n";
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo "var slides=new Array();" . "\n";
returnimages();
?>
with:
PHP Code:
<?php
function returnimages($dirname = './images/') {
$pattern = '#\.(jpg|jpeg|png|gif|bmp)$#i';
$files = array();
if($handle = opendir($dirname)){
while(($file = readdir($handle)) !== false){
if(preg_match($pattern, $file)){
array_push($files, "\t['" . $dirname . $file . "', '', '']");
}
}
closedir($handle);
natsort($files);
}
return "var slides = [\n" . implode(",\n", $files) . "\n];\n";
}
echo returnimages();
?>
Bookmarks