dsfjnxjlbqv9812 2015-09-23 12:10
浏览 22

显示存储在public_html之外的图像数组

I want to display array of images as thumbnails in bootstrap, the images are stored outside the public directory or root. This is the code I used to display images before storing them outside the public directory.

<?php 
 foreach ($artist as $value) : ?>
 <div class="col-xm-6 col-sm-6 col-md-4 col-lg-4">
<div class="thumbnail">
<a href="info.php?id=<?php echo $value['uploads_id']; ?>"><img src="<?php echo trim($value['uploads_cover']); ?>"></a>
<div class="caption">
    <p><?php echo substr($value['title'], 0,29); ?></p>
    <hr>
    <p><?php echo substr($value['name'], 0,29); ?></p>
  </div>
  </div>
 </div>
 <?php endforeach;

enter image description here Now I have decided to store images outside the web root, I can't display them with foreach, Currently I can display one image with the following code.

image.php

<?php
 header('Content-type: image/jpeg');
 readfile('/opt/lampp/htdocs/images/Uploads/00-cover.jpg.png');

then in my src

<img src="image.php" alt="..." >

UPDATE Using suggested answer by Amarnasan

 <?php foreach ($images as $value) : ?>
 <li>
<a href="image.php?folder=<?php echo $artist[0]['upload_folder'].'&img='.$value;?>">
            <img src="image.php?folder=<?php echo $artist[0]['upload_folder'].'&img=th_'.$value;?>" alt="<?php echo $artist[0]['title'];?>"  />
      </a>
    </li>
 <?php endforeach; ?>

And my new image.php It's working after removing extensions. . '.jpg.png'

<?php
  header('Content-type: image/jpeg');
  readfile('/opt/lampp/htdocs/images/'. $_GET['folder'] . '/' . $_GET['img']);

Images are still not displaying, when I open dev console, image src displays src="image.php?folder=armin&img=th_21570.jpg"

  • 写回答

1条回答 默认 最新

  • dongzhunqiu4841 2015-09-23 12:21
    关注

    Pass the image name as parameter to image.php:

    <img src="image.php?img=00-cover" alt="..." >
    <img src="image.php?img=01-cover" alt="..." >
    

    and

    <?php
     header('Content-type: image/jpeg');
     readfile('/opt/lampp/htdocs/images/Uploads/'.$_GET['img'].'.jpg.png');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。