【问题标题】:store and get images in mysql using CodeIgniter使用 CodeIgniter 在 mysql 中存储和获取图像
【发布时间】:2013-12-11 06:16:43
【问题描述】:

我正在使用 WAMP 服务器,我想使用 CI 将图像上传到数据库中。数据库中的图像变量是 blob 数据类型。我的问题如下: 1)如何存储图像而不是文件名,我应该使用什么数据类型? 2) 如何从数据库中检索图像?

我的控制器

public function index()
    {

    $this->load->model('contact_model');

    if ($this->input->post('upload')) {

    $data['logo_name']= $this->input->post('name');
    $data['logo_image']=$_FILES['userfile']['name'];


    if($this->contact_model->do_upload()) {

    echo $this->upload->display_errors();

    }else {

    $this->contact_model->Save_image($data);

        }
     }
        $data['getlogo']=$this->contact_model->getlogo();
        $this->load->view('templates/header',$data);
  }

我的模特

  function do_upload() {

$this-> gallery_path=realpath( APPPATH.'./uploads');

    $config = array( 
        'allowed_types' => 'jpg|png|bmp', 
        'upload_path'=>$this->gallery_path, 
        'max_size'=>2000
    );

    $this->load->library('upload',$config);

    if ($this->upload->do_upload()) {

        echo "Upload success!";         
        $image_data=$this->upload->data();
    }
    else 
        {
            echo "Upload failed!";
            echo $this->upload->display_errors();
        }

}  

    function getlogo(){

    $this->db->where('logo_id',3);
    return $this->db->get('logo');
}
function save_image($data){


    $q= $this->db->insert('logo', $in);
    return $q;
    }

我的看法

<?php foreach ($getlogo->result() as $row){ ?>
                <a href="#" style="padding-right:1px">
                <img src="<?php echo base_url();?>/application/uploads/<?php echo $row->logo_image;}?>"
                height="200px" width="500px" /></a>

【问题讨论】:

标签: php mysql codeigniter


【解决方案1】:

关注this 将文件保存到blob

并使用

<img src="data:image/jpeg;base64,<?php echo base64_encode($image['file_data'])?>'"/>

用于显示图像

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    相关资源
    最近更新 更多