Php 使用codeigniter 3上传不同类型的文件?
是否可以使用两个输入文件上载不同类型的文件?我用两个输入创建了一个表单上传,现在我很困惑为什么即使我上传了不同名称的不同文件,文件名也是相同的 这是我的控制器:Php 使用codeigniter 3上传不同类型的文件?,php,codeigniter,file-upload,Php,Codeigniter,File Upload,是否可以使用两个输入文件上载不同类型的文件?我用两个输入创建了一个表单上传,现在我很困惑为什么即使我上传了不同名称的不同文件,文件名也是相同的 这是我的控制器: public function file_data() { $data['program'] = $this->input->post('program'); $this->load->library('upload'); $config['upload_path'] = './upl
public function file_data() {
$data['program'] = $this->input->post('program');
$this->load->library('upload');
$config['upload_path'] = './uploaded_files/laporan/absen';
$config['allowed_types'] = 'pdf';
$this->upload->initialize($config);
if (!$this->upload->do_upload('file_absen')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('tutor/upload_form', $error);
} else {
unset($config);
$config['upload_path'] = './uploaded_files/laporan/nilai';
$config['allowed_types'] = 'xls|xlsx';
$config['overwrite'] = FALSE;
//$config['max_size'] = '15000';
$this->upload->initialize($config);
if (!$this->upload->do_upload('file_nilai')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('tutor/upload_form', $error);
} else {
$upload_data = $this->upload->data();
//get the uploaded file name
$data['file_absen'] = $upload_data['file_name'];
$data['file_nilai'] = $upload_data['file_name'];
//store pic data to the db
$this->laporan_model->simpan_data($data);
redirect(base_url() . "tutor/laporan_np");
}
}
}
这是我的模型:
//fetch all data from db
function ambil_data(){
$all_files = $this->db->get('laporan');
return $files_pics->result();
}
//save datadata to db
function simpan_data($data){
$insert_data['program'] = $data['program'];
$insert_data['file_nilai'] = $data['file_nilai'];
$insert_data['file_absen'] = $data['file_absen'];
$query = $this->db->insert('laporan', $insert_data);
}
文件Nilai*:
文件Absen*:
您可以将您的条件重写为:
public function file_data() {
$data['program'] = $this->input->post('program');
$this->load->library('upload');
$config['upload_path'] = './uploaded_files/laporan/absen';
$config['allowed_types'] = 'pdf';
$this->upload->initialize($config);
if (!$this->upload->do_upload('file_absen')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('tutor/upload_form', $error);
} else {
$upload_data_absen = $this->upload->data(); // added this..
unset($config);
$config['upload_path'] = './uploaded_files/laporan/nilai';
$config['allowed_types'] = 'xls|xlsx';
$config['overwrite'] = FALSE;
//$config['max_size'] = '15000';
$this->upload->initialize($config);
if (!$this->upload->do_upload('file_nilai')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('tutor/upload_form', $error);
} else {
$upload_data_nilai = $this->upload->data(); // changed this..
//get the uploaded file name
$data['file_absen'] = $upload_data_absen['file_name']; // changed this..
$data['file_nilai'] = $upload_data_nilai['file_name']; // changed this..
//store pic data to the db
$this->laporan_model->simpan_data($data);
redirect(base_url() . "tutor/laporan_np");
}
}
}
你能发布你的$upload_数据数组吗?回响我从来没有想过在每个条件下更改名称$upload\U data。。非常感谢你,哈斯塔·达纳……这对我来说很有用: