ignore a file name in php array
im pretty new with php, i found a gallery script that takes all photos from a folder and displays them. I'm trying to make the array ignore all folders in this 'photos' folder named 'app_thumbnails'.
the code creating the array is:
//READ FILES AND FOLDERS
$files = array();
$dirs = array();
if ($handle = opendir($currentdir))
{
while (false !== ($file = readdir($handle)))
{
// Change filename to display date
$displaydate= date('jS M Y', strtotime($file));
// Load folders into array
if (is_directory($currentdir . "/" . $file))
{
if ($file != "." && $file != ".." )
{
// Set thumbnail to folder.jpg if found:
if (file_exists(GALLERY_ROOT . "photos/" . $file . "/folder.jpg"))
{
$dirs[] = array(
"name" => $file,
"date" => filemtime($currentdir . "/" . $file),
"html" => "<li><a href='?dir=" . urlencode(ltrim($_GET['dir'] . "/" . $file, "/")) . "'><em> " . $displaydate . "</em><span></span><img src='" . GALLERY_ROOT . "createthumb.php?filename=photos/" . $file . "/folder.jpg&size=$thumb_size' alt='$label_loading' /></a></li>");
} else
{
//Set thumbnail to first image found (if any):
unset ($firstimage);
$firstimage = getfirstImage("$currentdir/" . $file);
if ($firstimage != "") {
$dirs[] = array(
"name" => $file,
"date" => filemtime($currentdir . "/" . $file),
"html" => "<li><a href='?dir=" . urlencode(ltrim($_GET['dir'] . "/" . $file, "/")) . "'><em> " . $displaydate . "</em><span></span><img src='" . GALLERY_ROOT . "createthumb.php?filename=$thumbdir/" . $file . "/" . $firstimage . "&size=$thumb_size' alt='$label_loading' /></a></li>");
} else {
//If no folder.jpg or image is found, then display default icon:
$dirs[] = array(
"name" => $file,
"date" => filemtime($currentdir . "/" . $file),
"html" => "<li><a href='?dir=" . urlencode(ltrim($_GET['dir'] . "/" . $file, "/")) . "'><em> " . $displaydate . "</em><span></span><img src='" . GALLERY_ROOT . "images/folder_" . strtolower($folder_color) . ".png' width='$thumb_size' height='$thumb_size' alt='$label_loading' /></a><开发者_运维问答/li>");
}
}
}
}
you can see my gallery example here: http://design-wright.co.uk/bunker/gallery/gallery.php
thanks for your time guys. alsweet
Replace
if ($file != "." && $file != ".." )
with
if ($file != "." && $file != ".." && $file != "app_thumbnails")
try replacing the following:
if ($file != "." && $file != ".." )
by
if ($file != "." && $file != ".." && $file != 'app_thumbnails')
精彩评论