2010-11-16 67 views
2

即時通訊使用php很新,我發現了一個庫腳本,從文件夾中獲取所有照片並顯示它們。我試圖讓這個數組忽略名爲'app_thumbnails'的'照片'文件夾中的所有文件夾。在php數組中忽略文件名

的代碼創建數組:

//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>&nbsp;&nbsp;&nbsp;&nbsp;" . $displaydate . "</em><span></span><img src='" . GALLERY_ROOT . "createthumb.php?filename=photos/" . $file . "/folder.jpg&amp;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>&nbsp;&nbsp;&nbsp;&nbsp;" . $displaydate . "</em><span></span><img src='" . GALLERY_ROOT . "createthumb.php?filename=$thumbdir/" . $file . "/" . $firstimage . "&amp;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>&nbsp;&nbsp;&nbsp;&nbsp;" . $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>"); 
         } 
        } 
       } 
      } 

,你可以在這裏看到我的畫廊例如:http://design-wright.co.uk/bunker/gallery/gallery.php

感謝您的時間傢伙。 alsweet

回答

4

嘗試更換如下:

if ($file != "." && $file != "..") 

通過

if ($file != "." && $file != ".." && $file != 'app_thumbnails') 
+0

非常感謝,很棒! – alsweet 2010-11-16 16:05:30

+0

很高興幫助:) – acm 2010-11-16 16:07:23

5

更換

if ($file != "." && $file != "..") 

if ($file != "." && $file != ".." && $file != "app_thumbnails")