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!