-1
我正在使用WAMP服務器,並且想要使用CI在數據庫中上傳圖像。數據庫中的圖像變量是blob數據類型。我的問題如下: 1)如何存儲圖像而不是文件名,我應該使用哪些數據類型? 2)如何從數據庫中檢索圖像?使用CodeIgniter在mysql中存儲和獲取圖像
我控制器
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>
http://www.techcubetalk.com/2009/01/tutorial-on-how-to-store-images-in-mysql-blob-field/ –
可能重複[CodeIgniter:在數據庫中存儲圖像?](http://stackoverflow.com/questions/2775284/codeigniter-storing-an-image-in-the-database) – zzlalani