iOS multi-image upload interface, help?

Source: Internet
Author: User
I am on the web side of the multi-image upload test is correct, can upload images, can also be entered into the database, but not in iOS, can only upload a picture, will be covered by other images, what is the reason, for help, urgent urgent!!!!!!!!

Model Layer

Public function up () {

    if($_FILES['upload']['error'][0]==0){        //调用文件上传的方法        $info = $this ->upload();        foreach($info as $info_v){

Intercept file suffix name, determine what type of file

            $suffix = substr(strrchr($info_v['upload'],'.'),1);

Determines whether the file classification is given

Determine file type

Image

                if($suffix=='jpg'||$suffix=='gif'||$suffix=='png'||$suffix=='jpeg'){                    $type=1;                }else

Video

                if($suffix=='mp4'){                    $type=2;                }else

Music

                if($suffix=='mp3'){                    $type=4;                }else{                    $type=3;                }            

Add an upload file to a database

            $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 '上传失败';        }    }}

Upload method

protected function upload(){

$files = $_files[' upload ');

    $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;    }}

Controller Layer
Uploading files

public function index(){    if(IS_POST){    //     调用模型层的方法        $id = $this->upload->up();        if(is_numeric($id)){            $data = array(                    'success'=>true,                    'message'=>'上传成功',                    'data'=>'',            );            echo json_encode($data);        }    }}

Reply content:

I am on the web side of the multi-image upload test is correct, can upload images, can also be entered into the database, but not in iOS, can only upload a picture, will be covered by other images, what is the reason, for help, urgent urgent!!!!!!!!

Model Layer

Public function up () {

    if($_FILES['upload']['error'][0]==0){        //调用文件上传的方法        $info = $this ->upload();        foreach($info as $info_v){

Intercept file suffix name, determine what type of file

            $suffix = substr(strrchr($info_v['upload'],'.'),1);

Determines whether the file classification is given

Determine file type

Image

                if($suffix=='jpg'||$suffix=='gif'||$suffix=='png'||$suffix=='jpeg'){                    $type=1;                }else

Video

                if($suffix=='mp4'){                    $type=2;                }else

Music

                if($suffix=='mp3'){                    $type=4;                }else{                    $type=3;                }            

Add an upload file to a database

            $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 '上传失败';        }    }}

Upload method

protected function upload(){

$files = $_files[' upload ');

    $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;    }}

Controller Layer
Uploading files

public function index(){    if(IS_POST){    //     调用模型层的方法        $id = $this->upload->up();        if(is_numeric($id)){            $data = array(                    'success'=>true,                    'message'=>'上传成功',                    'data'=>'',            );            echo json_encode($data);        }    }}

iOS off your interface is not a multi-image one-time request! or multi-image upload multiple times!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.