如何仅显示缩略图图像?

时间:2016-12-19 11:33:54

标签: php image loops foreach

我在上传目录中的一些图片,并且在目录中上传了两种类型的图片(缩略图和原始图片),我只想显示缩略图图像但无法显示隐藏原始图像。

以下是上传图片文件的示例

原始档案:5857bf4b74dcb.jpg

缩略图文件:thumb_5857bf4b74dcb.jpg

<?php 
if ($handle = opendir("uploads/")) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") { ?>
<div class="col-md-2">
<div class="well well-sm text-center">
<img src="<?php echo $fd.'uploads/'.$_GET['f'].'/'.$entry; ?>" alt="<?php echo str_replace(" .jpg ", " ", $entry); ?>" class="img-thumbnail" />
</div>
</div>        
<?php } } closedir($handle); }

1 个答案:

答案 0 :(得分:1)

您可以使用strstr()strrpos()检查文件名是否thumb_

尝试

if ($handle = opendir("uploads/"))
{
  while (false !== ($entry = readdir($handle)))
  {
    if ($entry != "." && $entry != "..")
      {
        if( stristr($entry, 'thumb_'))
        {

      ?>
  <div class="col-md-2">
  <div class="well well-sm text-center">
  <img src="<?php echo $fd.'uploads/'.$_GET['f'].'/'.$entry; ?>" alt="<?php echo str_replace(" .jpg ", " ", $entry); ?>" class="img-thumbnail" />
  </div>
  </div>        
  <?php
        }
    }
  }
  closedir($handle);
}