2014-02-05 60 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

相關問題