I'm trying to create a dynamic image gallery script, so that a client, once I'm done with the site, can upload images via FTP and the site will update automatically. I'm using a script I found on here, but I cannot get it to work for the life of me. The PHP writes information, but will never actually write out the images it's supposed to find in the directory. Not sure why. Demo here and you can see the working code (without PHP) here.
<?php
function getDirTree($dir,$p=true) {
$d = dir($dir);$x=array();
while (false !== ($r = $d->read())) {
if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true)) {
$x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
}
}
foreach ($x as $key => $value) {
if (is_dir($dir.$key."/")) {
$x[$key] = getDirTree($dir.$key."/",$p);
}
}
ksort($x);
return $x;
}
$path = "../images/bettydew/";
$tree = getDirTree($path);
echo '<ul class="gallery">';
foreach($tree as $element => $eval) {
if (is_array($eval)) {
foreach($eval as $file => $value) {
if (strstr($file, "png")||strstr($file, "jpg")||strstr($file, "bmp")||strstr($file, "gif")) {
$item = $path.$file;
echo '<a href="javascript:void(0);"><img src="'.$item.'" alt="'.$item.'"/></a>';
}
}
}
}
echo '</ul>';
?>