I want to list all .jpg files in some directory and put result on page. When I run script using http://site.bogus/script.php it works fine. But when im triyng to run it using a {php} include("/whole/dir/script.php"); {/php} it dont give me list of files but ony write
"image(s) found in this directory.". How to repair it? Anybody have idea? Thanks in advance.
This is code of my directory lister.
Code: Select all
<?
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 "<a href=\"$files\">$files</a>\n<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);
?>