我有一个表单,其中包含两个选择文件按钮,一个用于图像,第二个用于文件上传,但在其中,我的图像功能在其中正常工作,但是当我上传我的文档文件时,这无法正常工作。请帮助我
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++) {
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './upload/article_img/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
}
$names= implode(',', $name_array);
$this->load->database();
$db_data = array(
'article_id'=> $is_product_saved,
'image_title'=>json_encode($this->input->post('image_title')),
'file_name'=> $names,
'created_date' => date('Y-m-d H:i:s')
);
$is_saved_img = $this->site_model->save_data('article_image',$db_data);
if($_FILES["files"]["name"] != ''){
$output = '';
$config["upload_path"] = './upload/article_doc/';
$config["allowed_types"] = 'txt|pdf|doc';
//$this->load->library('upload', $config);
$this->upload->initialize($config);
for($count = 0; $count<count($_FILES["files"]["name"]); $count++)
{
$_FILES["file"]["name"] = $_FILES["files"]["name"][$count];
$_FILES["file"]["type"] = $_FILES["files"]["type"][$count];
$_FILES["file"]["tmp_name"] = $_FILES["files"]["tmp_name"][$count];
$_FILES["file"]["error"] = $_FILES["files"]["error"][$count];
$_FILES["file"]["size"] = $_FILES["files"]["size"][$count];
if($this->upload->do_upload('file'))
{
$data = $this->upload->data();
$output[] =$data["file_name"];
}
}
$name_doc= implode(',', $output);
$db = array(
'doc_name'=> $name_doc,
'article_id'=> $is_product_saved,
'doc_title'=>json_encode($this->input->post('document_title')),
'created_date' => date('Y-m-d H:i:s')
);
$is_saved_img = $this->site_model->save_data('article_document',$db);
}
从其工作中删除}
if statement
if($this->upload->do_upload('file'))
{
$data = $this->upload->data();
$output[] =$data["file_name"];
}
// } remove this extra bracket because its end `for loop`