Page 2 of 2

Posted: Wed Jun 11, 2003 9:05 am
by mesz
I think this all down to the directory that I 'm opening - as with all my problems posted on this forum it is going to come down to the syntax of the directory / folder I am opening...

Posted: Wed Jun 11, 2003 11:36 am
by mesz
I've done it - thanks for all you help everybody.
My page still needs tidying up, and security features adding, but essentially here is the finished version of view.php:

Code: Select all

<?
function CheckExt($filename, $ext) {
$passed = FALSE;
$testExt = "\.".$ext."$";
if (eregi($testExt, $filename)) {
$passed = TRUE;
}
return $passed;
}
$exts = array("gif","jpg$|\\.jpeg","png","bmp");

echo "<b>Images in this folder:</b>";
$dir = opendir(".");
$files = readdir($dir);

while (false !== ($files = readdir($dir))) {
foreach ($exts as $value) {
if (CheckExt($files, $value)) {
echo "<img src='$files' >\n";  
$count++; 
break;}
}
}
echo $count." image(s) found in this directory.\n";
echo "<a href="".$_SERVER["PHP_SELF"]."">Refresh</a>\n";
closedir($dir);
?>
I put the view.php code inside the subdirectory and then made sure only image files could be displayed - otherwise blank image squares were showing to represent folders and php and html pages - thats what the red squares were.
I'll probably screw this up royally now whilst tidying and be back again...but cheers for your help, it was invaluable.