2014-02-05 62 views
0

在我的页面中,我创建了一个包含名称,电子邮件,密码等不同字段的表单,现在我必须上传图像并存储在我的数据库中。任何人都会发送包含图片上传文件在内的所有字段的代码。我必须多次尝试,图像无法上传到我的数据库中。如何将图像保存到我的数据库中?

我控制器

function activity() { 
    $this->load->library('form_validation'); 
    //field name,error message, validation rules 
    $this->form_validation->set_rules('activityid', 'Activity Id', 'trim|required'); 
    $this->form_validation->set_rules('hostid', 'Host Id', 'trim|required'); 
    $this->form_validation->set_rules('activityname', 'Activity Name', 'trim|required'); 
    $this->form_validation->set_rules('date', 'Date', 'trim|required'); 
    $this->form_validation->set_rules('venue', 'Venue', 'trim|required'); 
    $this->form_validation->set_rules('typeofactivity', 'Type of Activity', 'trim|required'); 
    $this->form_validation->set_rules('conductedby', 'Conducted By', 'trim|required'); 
    if ($this->form_validation->run() == FALSE) { 
     //$this->load->view('signup_form'); 
     $this->activity_reg(); 
    } else { 
     $this->load->model('membership_model'); 

     $query = $this->membership_model->activity(); 

     if ($query) { 
      $data['main_content'] = 'signup_successful'; 
      $this->load->view('includes/templates', $data); 
     } else { 
      $this->load->view('activity'); 
     } 
    } 
} 

我的模型是

function activity() { 
    $new_member_insert_data = array(
     'activityid' => $this->input->post('activityid'), 
     'hostid' => $this->input->post('hostid'), 
     'activityname' => $this->input->post('activityname'), 
     'date' => $this->input->post('date'), 
     'venue' => $this->input->post('venue'), 
     'typeofactivity' => $this->input->post('typeofactivity'), 
     'conductedby' => $this->input->post('conductedby') 
    ); 

    $this->load->database(); 
    $insert = $this->db->insert('activity', $new_member_insert_data); 
    return $insert; 
} 
+0

为什么图像数据库保存?只使用它的名字而不是图片本身。 – Abhishek

+0

向我发送代码,我会尝试 – abu

+0

检查下面的链接它会给你一个想法http://ellislab.com/codeigniter%20/user-guide/libraries/file_uploading.html分配后只更新数据库表中的uniqueimage名称 – Abhishek

回答

0

你没有保存图像在数据库中。 这里是你可以做什么让你的应用程序安全性: 当您上传图片:

  • 验证图像
  • 在一个变量
  • 确保其名称重命名为标准名称
  • 上传它在一个安全的文件夹
  • 存储图像的原始和重新命名的名称数据库(不是图像本身)
  • 检索图像时,只定义图像的路径和呼应新名字。

这应该做工精细

或者如果你真的想插入图片到数据库,按照这个网页。它应该给你正是你想要的!

http://mrarrowhead.com/index.php?page=store_images_mysql_php.php

+0

任何编码.. ... – abu

+0

检查更新的答案!它应该给你一个好主意! – ashish

相关问题