I know how to reverse an array when data has been written to a .dat / .txt file, but how do you reverse the array when displaying a directory contents?
( It is not an array - I guess the first step will be to turn teh directory contents into an array - how do I do this? )
Code: Select all
<?php
<?
function CheckExt($filename, $ext) {
$passed = FALSE;
$testExt = "\.".$ext."$";
if (eregi($testExt, $filename)) {
$passed = TRUE;
}
return $passed;
}
//Define an array of common extensions.
$exts = array("gif","jpg$|\\.jpeg","png","bmp");
echo "<b>Images in this folder:</b><br>";
$dir = opendir(".");
$files = readdir($dir);
while (false !== ($files = readdir($dir))) {
foreach ($exts as $value) {
if (CheckExt($files, $value)) {
echo "<img src='$files'><br />";
$count++; //Keep track of the total number of files.
break; //No need to keep looping if we've got a match.
}
}
}
echo $count." image(s) found in this directory.\n";
?>
<?
closedir($dir);
?>
?>