在codeigniter中显示来自数据库的图像

时间:2015-08-19 15:51:26

标签: php mysql codeigniter

我已将图像上传到数据库。现在我想在另一个页面显示。但我不知道该怎么做。我已经在互联网上找到了我在网站上找到的视图图像的代码。但它不起作用任何人都可以帮助我。

我的观点

    <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                         Plan

                        </h1>
                        <ol class="breadcrumb">
                            <li>
                                <i class="fa fa-dashboard"></i>  <a href="index.html">Home</a>
                            </li>
                            <li class="active">
                                <i class="fa fa-file"></i> Floor Plan
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->


<body>

    <div id="response"></div>
<div class="well">

<div class="container">
    <div class="row">

    <table>
     <tr>


      <td><strong>&nbsp; &nbsp; Title</strong></td>
      <td><strong>&nbsp; &nbsp; Client </strong></td>
      <td><strong>&nbsp; &nbsp; Draw By</strong></td>
      <td><strong>&nbsp; &nbsp;Floor Plan</strong></td>
    </tr>
     <?php foreach($post as $post){?>
     <tr>
<!--         <td><?php //echo $post->id;?></td>-->
         <td><?php echo $post->id ; echo '&nbsp; &nbsp;';?></td>
<!--         <td><?php echo $post->title ; echo '&nbsp; &nbsp;';?></td>
         <td><?php echo $post->firstname ; echo '&nbsp;';?><?php echo $post->lastname  ; echo '&nbsp; &nbsp;'?></td>
         <td><?php echo $post->first_name ; echo '&nbsp;';?><?php echo $post->last_name  ; echo '&nbsp; &nbsp;'?></td>-->
         &nbsp; &nbsp;<td><?php echo $post->image ; echo '&nbsp; &nbsp; &nbsp;  &nbsp;&nbsp; &nbsp; &nbsp;  &nbsp;'?></td>
      </tr>  
      do { 
echo "<img src='path/to/image.php?id=".$row['id']."' />"; 
} while($row = mysql_fetch_assoc(res));

     <?php }

     ?>  
   </table>


    </div>
</div>
</div>


</body>
</html>

控制器

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Floor_plan extends CI_Controller{

public function __construct() {
        parent::__construct();
        $this->load->database(); // load database
        $this->load->model('floor_model');


}

    public function index(){  

 $data['post'] = $this->floor_model->get_plan(); // calling Post model method getPosts() 
        $this->load->view('user_include/header');
        $this->load->view('plan/floor',$data);
    }



 }

?>

模型

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

<?php
class Floor_model extends CI_Model {


function get_plan(){
  $this->db->select("floor_plan.id,floor_plan.image");
  $this->db->from('floor_plan');

  $query = $this->db->get();
  return $query->result();
}
}
?>

2 个答案:

答案 0 :(得分:1)

请在图像源中提供完整路径,如 -

<?

答案 1 :(得分:0)

<?php echo "<img src='" . base_url().$post->image."' width=150px; height=100px;>";?></td>

此代码工作正常