Sorry - didn't clarify. The function I wrote for PHP 4 is just fine; no need to modify it. It already gets rid of any directories in the array. To make it PHP 5 compatible, all you do is use function_exists() to know whether to define it or not, like this:
if(!function_exists('scandir')) {
function scandir($dir) {
global $files;
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if(!is_dir($filename)) $files[] = $filename;
}
return $files;
}
}
Since you can't modify a function already defined (like in PHP 5 in this case), you need to modify the data when you process it. Here is where you would check for "." or ".." in our code:
for($i = (($page-1)*$limit), $stop = ((($page-1)*$limit)+$limit); $i < $stop && $i < count($fileArray); $i++) {
echo '<a href="'.$dir.$fileArray[$i].'"><img src="' .$thumb.$fileArray[$i].'" border="0"></a><br>';
// do whatever you want with the filename here...
}
An example solution would be to check if $fileArray[$i] is '.' or '..' or not. If it is, add 1 back to the "stop" or limit variable (so that we aren't shorted an image or two on the output), and continue on to the next iteration. Something like this:
for($i = (($page-1)*$limit), $stop = ((($page-1)*$limit)+$limit); $i < $stop && $i < count($fileArray); $i++) {
if($fileArray[$i] == '.' || $fileArray[$i] == '..') {
$stop++;
continue;
}
echo '<a href="'.$dir.$fileArray[$i].'"><img src="' .$thumb.$fileArray[$i].'" border="0"></a><br>';
// do whatever you want with the filename here...
}
I believe that would do the trick for PHP 4+ compatibility.