我编写了PHP sctipt,它从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_'前缀的图像?
答案 0 :(得分:2)
您可以更改此行:
if($file=='.' || $file == '..') continue;
到该行:
if ($file=='.' || $file == '..' || !preg_match("/^thumb/",$file)) continue;
如果文件没有以拇指开头,它会跳过while循环。