My multi-image upload test on the web side is correct. I can upload images and enter them into the database. However, it does not work on iOS. I can only upload one image and it will overwrite other images. What is the reason for this? Please help. Urgent! Urgent! ! ! ! ! ! ! !
Model layer
public function up(){
<code> if($_FILES['upload']['error'][0]==0){ //调用文件上传的方法 $info = $this ->upload(); foreach($info as $info_v){</code>
//Intercept the file extension name to determine what type of file it is
<code> $suffix = substr(strrchr($info_v['upload'],'.'),1);</code>
// Determine whether the file classification is given
// Determine file type
// Pictures
<code> if($suffix=='jpg'||$suffix=='gif'||$suffix=='png'||$suffix=='jpeg'){ $type=1; }else</code>
//Video
<code> if($suffix=='mp4'){ $type=2; }else</code>
// Music
<code> if($suffix=='mp3'){ $type=4; }else{ $type=3; } </code>
//Add uploaded files to database
<code> $id = $this->add(array('user_id'=>1,'upload_url'=>$info_v['upload'],'c_time'=>NOW_TIME,'size'=>$info_v['size'],'type'=>$type)); } if($id){ return $id; }else{ return '上传失败'; } } } </code>
//Upload method
<code>protected function upload(){</code>
// $files = $_FILES['upload'];
<code> $upload = new \Think\Upload();// 实例化上传类 //C方法是用来读取配置信息 $upload->maxSize = C('maxSize') ;// 设置附件上传大小 $upload->exts = C('exts');// 设置附件上传类型 $upload->savePath = C('savePath'); // 设置附件上传目录 $upload->saveName = C('saveName'); // 设置上传文件的保存规则 $upload->rootPath = C('rootPath'); // 上传文件 $info = $upload->upload(); // print_r($info);die; $img_arr=array(); if(!$info) { // 上传错误提示错误信息 return $upload->getError(); }else{ foreach ($info as $k=>$v){ //拼接文件存储路径 $img_url = C('img_path').$v['savepath'].$v['savename']; $img_arr[$k]['upload']= $img_url; $img_arr[$k]['size']= $v['size']; } return $img_arr; } } </code>
Controller layer
//Upload files
<code>public function index(){ if(IS_POST){ // 调用模型层的方法 $id = $this->upload->up(); if(is_numeric($id)){ $data = array( 'success'=>true, 'message'=>'上传成功', 'data'=>'', ); echo json_encode($data); } } }</code>
My multi-image upload test on the web side is correct. I can upload images and enter them into the database. However, it does not work on iOS. I can only upload one image and it will overwrite other images. What is the reason for this? Please help. Urgent! Urgent! ! ! ! ! ! ! !
Model layer
public function up(){
<code> if($_FILES['upload']['error'][0]==0){ //调用文件上传的方法 $info = $this ->upload(); foreach($info as $info_v){</code>
// Intercept the file suffix name to determine what type of file it is
<code> $suffix = substr(strrchr($info_v['upload'],'.'),1);</code>
// Determine whether the file classification is given
// Determine file type
// Pictures
<code> if($suffix=='jpg'||$suffix=='gif'||$suffix=='png'||$suffix=='jpeg'){ $type=1; }else</code>
//Video
<code> if($suffix=='mp4'){ $type=2; }else</code>
// Music
<code> if($suffix=='mp3'){ $type=4; }else{ $type=3; } </code>
//Add uploaded files to database
<code> $id = $this->add(array('user_id'=>1,'upload_url'=>$info_v['upload'],'c_time'=>NOW_TIME,'size'=>$info_v['size'],'type'=>$type)); } if($id){ return $id; }else{ return '上传失败'; } } } </code>
//Upload method
<code>protected function upload(){</code>
// $files = $_FILES['upload'];
<code> $upload = new \Think\Upload();// 实例化上传类 //C方法是用来读取配置信息 $upload->maxSize = C('maxSize') ;// 设置附件上传大小 $upload->exts = C('exts');// 设置附件上传类型 $upload->savePath = C('savePath'); // 设置附件上传目录 $upload->saveName = C('saveName'); // 设置上传文件的保存规则 $upload->rootPath = C('rootPath'); // 上传文件 $info = $upload->upload(); // print_r($info);die; $img_arr=array(); if(!$info) { // 上传错误提示错误信息 return $upload->getError(); }else{ foreach ($info as $k=>$v){ //拼接文件存储路径 $img_url = C('img_path').$v['savepath'].$v['savename']; $img_arr[$k]['upload']= $img_url; $img_arr[$k]['size']= $v['size']; } return $img_arr; } } </code>
Controller layer
//Upload files
<code>public function index(){ if(IS_POST){ // 调用模型层的方法 $id = $this->upload->up(); if(is_numeric($id)){ $data = array( 'success'=>true, 'message'=>'上传成功', 'data'=>'', ); echo json_encode($data); } } }</code>
When ios uses your interface, does it request multiple images at once? Or upload multiple pictures multiple times!