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 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算