/** * 添加图片 */ public function do_upload() { $img=$_FILES['img_log']; $new=array(); $count=count($img['name']); for($i=0;$i<$count;$i++){ $new[$i]=""; } foreach($new as $key=>$val) { $new[$key]['name'] = $img['name'][$key]; $new[$key]['type'] = $img['type'][$key]; $new[$key]['tmp_name'] = $img['tmp_name'][$key]; $new[$key]['error'] = $img['error'][$key]; $new[$key]['size'] = $img['size'][$key]; } foreach ($new as $key=>$val){ $_FILES['userfile']=$val; if(!is_dir('./Public/uploads/'.date('Y-m-d').'/')){ mkdir('./Public/uploads/'.date('Y-m-d').'/'); } $config['upload_path'] = './Public/uploads/'.date('Y-m-d').'/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size']=10*1024; $config['encrypt_name']=true; $this->load->library('upload', $config); if (!$this->upload->do_upload()){ $error = array('error' => $this->upload->display_errors()); echo $error; } else { $info[] = array('upload_data' => $this->upload->data()); } } foreach($info as $key=>$val){ foreach($val as $k=>$v){ $new[$key]['img_log']='./uploads/'.date('Y-m-d').'/'.$v['file_name']; } } $news=array(); foreach($new as $key=>$val){ $news[$key]['img_log']=$val['img_log']; $news[$key]['bid']=3000; } foreach($news as $key=>$val){ $add=$this->db->insert('picture',$val); } if($add){ redirect("User/show"); } }
多文件上传
最新推荐文章于 2021-11-01 13:34:46 发布