Ios multi-image Upload API for help?

Source: Internet
Author: User
The multi-image upload test on the web end is correct. you can upload images or enter the database, but not on ios. you can only upload one image and overwrite other images, what is the reason for this? for help, please be in a hurry !!!!!!!! Model layer publicfunctionup (){... the multi-image upload test on the web end is correct. you can upload images or enter the database, but not on ios. you can only upload one image and overwrite other images, what is the reason for this? for help, please be in a hurry !!!!!!!!

Model layer

Public function up (){

If ($ _ FILES ['upload'] ['error'] [0] = 0) {// call the file upload method $ info = $ this-> upload (); foreach ($ info as $ info_v ){

// Truncate the file suffix to determine the type of file

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

// Determine whether the file category is specified

// Determine the 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 the uploaded file to the 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 failed ';}}}

// Upload method

protected function upload(){

// $ Files = $ _ FILES ['upload'];

$ Upload = new \ Think \ Upload (); // The instantiated upload class // C method is used to read configuration information $ upload-> maxSize = C ('maxsize '); // Set the attachment upload size $ upload-> exts = C ('exts'); // Set the attachment upload type $ upload-> savePath = C ('savepath '); // Set the attachment upload directory $ upload-> saveName = C ('savename'); // Set the storage rules for uploaded files $ upload-> rootPath = C ('rootpath '); // upload the file $ info = $ upload-> upload (); // print_r ($ info); die; $ img_arr = array (); if (! $ Info) {// upload error message return $ upload-> getError ();} else {foreach ($ info as $ k => $ v) {// spliced file storage path $ 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
// Upload a file

Public function index () {if (IS_POST) {// call the model layer method $ id = $ this-> upload-> up (); if (is_numeric ($ id )) {$ data = array ('success' => true, 'message' => 'uploaded successfully', 'data' => '',); echo json_encode ($ data );}}}

Reply content:

The multi-image upload test on the web end is correct. you can upload images or enter the database, but not on ios. you can only upload one image and overwrite other images, what is the reason for this? for help, please be in a hurry !!!!!!!!

Model layer

Public function up (){

If ($ _ FILES ['upload'] ['error'] [0] = 0) {// call the file upload method $ info = $ this-> upload (); foreach ($ info as $ info_v ){

// Truncate the file suffix to determine the type of file

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

// Determine whether the file category is specified

// Determine the 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 the uploaded file to the 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 failed ';}}}

// Upload method

protected function upload(){

// $ Files = $ _ FILES ['upload'];

$ Upload = new \ Think \ Upload (); // The instantiated upload class // C method is used to read configuration information $ upload-> maxSize = C ('maxsize '); // Set the attachment upload size $ upload-> exts = C ('exts'); // Set the attachment upload type $ upload-> savePath = C ('savepath '); // Set the attachment upload directory $ upload-> saveName = C ('savename'); // Set the storage rules for uploaded files $ upload-> rootPath = C ('rootpath '); // upload the file $ info = $ upload-> upload (); // print_r ($ info); die; $ img_arr = array (); if (! $ Info) {// upload error message return $ upload-> getError ();} else {foreach ($ info as $ k => $ v) {// spliced file storage path $ 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
// Upload a file

Public function index () {if (IS_POST) {// call the model layer method $ id = $ this-> upload-> up (); if (is_numeric ($ id )) {$ data = array ('success' => true, 'message' => 'uploaded successfully', 'data' => '',); echo json_encode ($ data );}}}

Does ios send multiple requests when you use your interface! Or upload multiple images!

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.