我对文件上传有点问题。我正在尝试上传两个文件,但由于某种原因,第一个文件被上传了两次,并且没有第二个文件的踪迹。我究竟做错了什么?
文件上传功能(模型):
public function file_upload($folder, $allowed_type, $max_size = 0, $max_width = 0, $max_height = 0)
{
$folder = $this->path . $folder;
$files = array();
$count = 0;
foreach ($_FILES as $key => $value) :
$file_name = is_array($value['name']) ? $value['name'][$count] : $value['name'];
$file_name = $this->global_functions->char_replace($file_name, '_');
$count++;
$config = array(
'allowed_types' => $allowed_type,
'upload_path' => $folder,
'file_name' => $file_name,
'max_size' => $max_size,
'max_width' => $max_width,
'max_height' => $max_height,
'remove_spaces' => TRUE
);
$this->load->library('image_lib');
$this->image_lib->clear();
$this->load->library('upload', $config);
if (!$this->upload->do_upload($key)) :
$error = array('error' => $this->upload->display_errors());
return FALSE;
else :
$file = $this->upload->data();
$files[] = $file['file_name'];
endif;
endforeach;
if(empty($files)):
return FALSE;
else:
return implode(',', $files);
endif;
}
功能表单文件上传(控制器):
public function dokument_insert()
{
$this->admin_login_check();
$dokument =explode(',', $this->doc->file_upload('/doc', 'pdf|PDF|doc|docx') );
var_dump($dokument);
$data = array(
'naziv' => $this->input->post('naziv_srb'),
'opis' => $this->input->post('opis_srb'),
'path_pdf' => $dokument[0],
'path_doc' => $dokument[1],
'kategorija_id' => $this->input->post('kategorija'),
'jezik_id' => $this->input->post('jezik')
);
$this->doc->save($data);
}
文件表格的一部分(查看):
<label for="dokument_pdf">Dokument PDF</label>
<input type="file" name="pdf" id="dokument_pdf">
<label for="dokument_doc">Dokument DOC</label>
<input type="file" name="doc" id="dokument_doc">