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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应