douliang1369 2017-02-20 04:31
浏览 34
已采纳

如何显示图像Codeigniter

I have uploaded an image through a form and successfully stored it in a uploads directory and I have also successfully stored the full path of the image in my database.

But I am facing a problem with showing the image in view :

view :

                 <div class="deal-top-top">
        <?php foreach($getAll as $rec) { ?>
            <div class="col-md-3 top-deal-top">
                <div class=" top-deal">
                    <a href="single.html" class="mask"><img src="<?php echo base_url('upload/screenshoot/').$rec->ss;?>"class="img-responsive zoom-img" alt=""></a>
                 <span class="four"><?php echo $rec->data_kategori;?></span>
                    <div class="deal-bottom">
                        <div class="top-deal1">
                            <h5><a href="single.html"><?php echo $rec->nama_aplikasi;?></a></h5>
                            <p>Instansi: <?php echo $rec->nama_instansi;?></p>
                        </div>
                        <div class="top-deal2">
                            <a href="single.html" class="hvr-sweep-to-right more">More</a>
                        </div>
                    <div class="clearfix"> </div>
                    </div>
                </div>
            </div>
             <?php } ?>  
        <div class="clearfix"> </div>
    </div>       

upload/screenshoot is uploads directory path, ss is the data name in database..

Controller

    $this->load->view('produk_view',['getKategori' =>$getKategori,'getAll' =>$getAll]);

if test with array :

ss is the part of getAll query:

  Array
  (
    [0] => stdClass Object
    ....
        [ss] => 1487492623549.PNG
    ....
    )

Error :

A PHP Error was encountered

Severity: Error

Message: Cannot use object of type stdClass as array

Thank you

  • 写回答

2条回答 默认 最新

  • douzhai1182 2017-02-20 04:46
    关注

    Just try with $rec->ss; because you have array having objects.

       echo $rec->ss;//prints 1487492623549.PNG
    

    UPDATE

    in order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php:

    $autoload['helper'] = array('url');
    

    Or, manually:

    $this->load->helper('url');
    

    Then set your image like this..

    <img src="<?php echo base_url('upload/screenshoot/'.$res->ss);?>" class="img-responsive zoom-img" alt="">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理