我正在尝试为上传文件创建多个配置。这是我的代码:
$config['upload_path'] = './upload/post';
$config['allowed_types'] = 'jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG';
$config['overwrite'] = TRUE;
$this->load->library('upload',$config);
$files = $_FILES;
$file=$_FILES['userfile']['name'];
$file_array=array();
for($i=0; $i<1; $i++){
$temp = explode(".",$files["userfile"]["name"][$i]);
$newfilename = mt_rand() . '.' .end($temp);
$_FILES['userfile']['name']= $newfilename;
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$file_array[$i]=$_FILES['userfile']['name'];
$this->upload->initialize($config);
$this->upload->do_upload();
$this->upload->data();
}
/* second upload file*/
$config2['upload_path'] = './upload/file';
$config2['allowed_types'] = 'jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG';
$this->load->library('upload', $config2);
$file_data = $_FILES;
$data_file=$_FILES['file_data']['name'];
$data_array=array();
for($x=0; $x<1; $x++){
$ex = explode(".",$file_data["file_data"]["name"][$x]);
$filename = mt_rand() . '.' .end($ex);
$_FILES['file_data']['name']= $filename;
$_FILES['file_data']['type']= $file_data['file_data']['type'][$x];
$_FILES['file_data']['tmp_name']= $file_data['file_data']['tmp_name'][$x];
$_FILES['file_data']['error']= $file_data['file_data']['error'][$x];
$_FILES['file_data']['size']= $file_data['file_data']['size'][$x];
$data_array[$x]=$_FILES['file_data']['name'];
$this->upload->initialize($config2);
$this->upload->do_upload();
$this->upload->data();
}
/*end upload file script*/
我如何设置多个配置?这可能吗?
您是否有其他方式上传具有不同名称文件标签的多个文件?
答案 0 :(得分:0)
您目前只是覆盖相同的配置。您需要创建一组上载配置。像这样:
$config['upload_configs'] = array();
$config['upload_configs'][0]['upload_path'] = './upload/post';
$config['upload_configs'][1]['upload_path'] = './upload/file';
....