2011-03-19 51 views
0

加載文件我從DIR寫PHP sctipt其中加載圖像和展示的圖片..PHP - 從DIR

directory = '../../gallery/glowna'; 
$thumb = '../../gallery/glowna'; 

$allowed_types=array('jpg','jpeg','gif','png'); 
$file_parts=array(); 
$ext=''; 
$title=''; 
$i=0; 

$dir_handle = @opendir($directory) or die("Błąd ! Skontaktuj się z administratorem SERWISU..."); 

while ($file = readdir($dir_handle)) 
{ 
    if($file=='.' || $file == '..') continue; 

    $file_parts = explode('.',$file); 
    $ext = strtolower(array_pop($file_parts)); 

    $title = implode('.',$file_parts); 
    $title = htmlspecialchars($title); 

    $nomargin=''; 

    if(in_array($ext,$allowed_types)) 
    { 
     if(($i+1)%3==0) $nomargin='nomargin'; 

     echo ' 

     <div class="pic '.$nomargin.'" style="background:url('.$thumb.'/'.$file.') no-repeat ; background-position:top center;"> 
     <form method="post" action="delete.php"> 
     <input type="checkbox" name="usun" value="'.$file.'" style="visibility:hidden;" checked="checked"/> 
     <input type="submit" name="submit" value="kasuj" style="float:right; font-size:9px; border:none; " /> 
     </form> 

     </div>'; 

     $i++; 
    } 
} 

     $usunac = $_POST['.$file.']; 
closedir($dir_handle); 

?> 

但在文件夾中我已經手腳的照片,我想只顯示大拇指,這是一個問題..

如何添加只顯示'thumb_'前綴的圖像的功能?

+1

什麼讓你不在文件名前面加上「thumb_」? – Raffael 2011-03-19 21:26:27

+0

Raffael1984 - 在DIR我有例如2文件 - 第一thumb_image.jpg和第二image.jpg,我不知道我怎麼只能顯示拇指.. – kraja 2011-03-19 21:32:08

回答

2

您可以將該行更改:

if($file=='.' || $file == '..') continue; 

到行:

if ($file=='.' || $file == '..' || !preg_match("/^thumb/",$file)) continue; 

這將使它跳過while循環,如果該文件沒有用拇指開始。

+0

嗨kraja ...只是想知道我的答案是否合適?如果是這樣 - 如果你能接受答案會很好。 – dotbill 2011-03-24 11:43:32