关于ci 多文件上传,各位帮忙看下,代码哪里有问题?
在视图做个文件上传的表单,里面有三个上传文件的input框 ,文件 name 定义 image1,image2,image3,下面的代码是在控制器里写的,做 了一个循环,循环三次上传文件,但是上传的到uploads的文件夹的文件名和我 echo出的$config['file_name']不一样啊。不知道问题出在哪里了?这么写逻辑有问题么?for($i=1;$i<4;$i++){
$filename=$_FILES['image'.$i]['name'];
$arr=explode('.',$filename);
$last='.'.array_pop($arr);
$config['upload_path'] ='./uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name']= uniqid().time().$last;
$name=$config['file_name'];
$this->library('upload','CI_', $config);
if (!$this->upload->do_upload('image'.$i)){
echo $this->upload->display_errors();
return ;
}
echo $config['file_name'];
1. $this->library('upload','CI_', $config); 这句话不对,应该是 $this->load->library();
2. $this->load->library() 只生效一次,也就是说你循环多少次都只会第一个config生效。
3. 所以,第二次调用文件上传类,不能用 load 应该用 initialize 方法,具体参考手册。
页:
[1]