【问题标题】:file not uploading in mysql using php codeigniter文件未使用 php codeigniter 在 mysql 中上传
【发布时间】:2014-03-10 23:49:54
【问题描述】:

以下是我使用 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。

【问题讨论】:

  • 您可以添加您的视图代码吗?
  • 好的,我将添加我的查看代码@kumar_v
  • 没有。编辑您的问题并添加。
  • 无需作为新问题提出。您可以自行编辑此问题。

标签: php mysql file codeigniter upload


【解决方案1】:

试试这个,你需要使用$_FILES["userfile"]而不是$_POST

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

而不是

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

【讨论】:

  • 我和你说的一样。但是,问题仍然存在!
  • 你能检查一下你在函数中是否正确获取了$param1 值!
猜你喜欢
  • 2014-03-11
  • 2013-02-12
  • 2014-03-11
  • 2015-05-11
  • 1970-01-01
  • 2012-08-11
  • 1970-01-01
  • 2014-03-16
  • 1970-01-01
相关资源
最近更新 更多