2014-02-12 63 views
0

以下是我使用codeigniter框架在mysql數據庫中上傳文件的代碼。 它有一些我無法找到的邏輯錯誤。請幫我找到它。文件不使用php codeigniter在mysql中上傳

function manage_prescription($param1 = '', $param2 = '', $param3 = '') 
{ 
    if ($this->session->userdata('laboratorist_login') != 1) 
     redirect(base_url() . 'index.php?login', 'refresh'); 

    if ($param1 == 'create_diagnosis_report') { 
     $data['report_type']  = $this->input->post('report_type'); 
     $data['document_type'] = $this->input->post('document_type'); 



     move_uploaded_file($_FILES["userfile"]["tmp_name"], "uploads/diagnosis_report/" . $_FILES["userfile"]["name"]); 
     $data['file_name'] = $_POST["userfile"]["name"]; 

     $data['prescription_id'] = $this->input->post('prescription_id'); 
     $data['description']  = $this->input->post('description'); 
     $data['timestamp']  = strtotime(date('Y-m-d') . ' ' . date('H:i:s')); 
     $data['laboratorist_id'] = $this->session->userdata('laboratorist_id'); 

     $this->db->insert('diagnosis_report', $data); 
     $this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_created')); 
     redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $this->input->post('prescription_id'), 'refresh'); 
    } 

    if ($param1 == 'delete_diagnosis_report') { 
     $this->db->where('diagnosis_report_id', $param2); 
     $this->db->delete('diagnosis_report'); 
     $this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_deleted')); 
     redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $param3, 'refresh'); 

    } else if ($param1 == 'edit') { 
     $page_data['edit_profile'] = $this->db->get_where('prescription', array(
      'prescription_id' => $param2 
     ))->result_array(); 
    } 
    $page_data['page_name']  = 'manage_prescription'; 
    $page_data['page_title'] = get_phrase('manage_prescription'); 
    $page_data['prescriptions'] = $this->db->get('prescription')->result_array(); 
    $this->load->view('index', $page_data); 
} 

當我運行此代碼時,它沒有提供任何錯誤。但是,它也不存儲該文件,並且它將數據庫中的file_name顯示爲NULL。

+0

可以添加您的視圖代碼? –

+0

好的我將添加我的視圖代碼@kumar_v – user3116267

+0

編輯您的問題並添加。 –

回答

0

試試這個,你需要使用的$_FILES["userfile"]代替$_POST

$data['file_name'] = $_FILES["userfile"]["name"]; 

,而不是

$data['file_name'] = $_POST["userfile"]["name"]; 
+0

我做了同樣的事情,但是,問題依然存在! – user3116267

+0

你能檢查你在函數內正確獲得'$ param1'的值嗎! –