PHP - 从 DIR 加载文件
我编写了 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_”前缀的图像的功能?
I wrote PHP sctipt which loading images from DIR and display a picture..
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);
?>
But in folder I have thumbs and big photos, I want display only thumb and it's a problem..
How can I add function displaing only images whith 'thumb_' prefix ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将此行:更改
为行:
如果文件不是以thumb开头,这将使其跳过while循环。
You could change this line:
to the line:
which would make it skip the while loop if it the file didn't begin with thumb.