iOS multiple image upload interface, help?

WBOY
Release: 2016-09-14 09:41:25
Original
1030 people have browsed it

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>
Copy after login
Copy after login

//Intercept the file extension name to determine what type of file it is

<code>            $suffix = substr(strrchr($info_v['upload'],'.'),1);</code>
Copy after login
Copy after login

// 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>
Copy after login
Copy after login

//Video

<code>                if($suffix=='mp4'){
                    $type=2;
                }else</code>
Copy after login
Copy after login

// Music

<code>                if($suffix=='mp3'){
                    $type=4;
                }else{
                    $type=3;
                }
            </code>
Copy after login
Copy after login

//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>
Copy after login
Copy after login

//Upload method

<code>protected function upload(){</code>
Copy after login
Copy after login

// $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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Reply content:

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>
Copy after login
Copy after login

// Intercept the file suffix name to determine what type of file it is

<code>            $suffix = substr(strrchr($info_v['upload'],'.'),1);</code>
Copy after login
Copy after login

// 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>
Copy after login
Copy after login

//Video

<code>                if($suffix=='mp4'){
                    $type=2;
                }else</code>
Copy after login
Copy after login

// Music

<code>                if($suffix=='mp3'){
                    $type=4;
                }else{
                    $type=3;
                }
            </code>
Copy after login
Copy after login

//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>
Copy after login
Copy after login

//Upload method

<code>protected function upload(){</code>
Copy after login
Copy after login

// $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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

When ios uses your interface, does it request multiple images at once? Or upload multiple pictures multiple times!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!