【发布时间】:2014-01-04 19:56:53
【问题描述】:
我是codeigniter的新手,请你帮我如何在codeigniter中上传多个文件(文档和图像)。
这是我的示例代码
查看代码
<label>Photo</label>
<input type="file" name="employee_photo" />
<label>Document</label>
<input type="file" name="employee_doc" />
控制器代码
function insertEmployee()
{
$query = $this->employee_model->insertEmployee();
if($query) {
$this->do_upload_image('employee_photo');
$this->do_upload_file('employee_doc');
}
}
function do_upload_image($field_name) {
$config['upload_path'] = './uploads/';
$config['upload_url'] = base_url()."uploads/";
$config['allowed_types'] = "gif|jpg|png|jpeg";
$config['overwrite'] = TRUE;$config['max_size'] = '1000KB';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload($field_name)) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('add_employee', $error); } else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('employee_listing', $data); }
}
function do_upload_file($field_name) {
$config_file['upload_path'] = './uploads/';
$config_file['upload_url'] = base_url()."uploads/";
$config_file['allowed_types'] = "pdf|doc|docx";
$config_file['encrypt_name'] = true;
$config_file['overwrite'] = TRUE;
$config_file['max_size'] = '1000KB';
$this->load->library('upload', $config_file);
if ( ! $this->upload->do_upload($field_name)) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('add_employee', $error);
} else {
$data_file = array('upload_data_file' => $this->upload->data());
$this->load->view('employee_listing', $data_file);
}
}
我尝试了谷歌,但我没有看到任何解决方案。
请帮忙。谢谢
【问题讨论】:
-
看看对你有没有帮助 => stackoverflow.com/questions/8377218/…
-
你应该使用多部分,不是吗?
标签: php codeigniter