gpt4 book ai didi

php - 使用 php codeigniter 未在 mysql 中上传文件

转载 作者:行者123 更新时间:2023-11-30 00:41:37 26 4
gpt4 key购买 nike

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

最佳答案

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

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

而不是

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

关于php - 使用 php codeigniter 未在 mysql 中上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21731566/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com