I have introduced a lot of topics for uploading multiple files directly in php, but I encountered multiple file uploads in thinkphp at the first time, so what are the differences and commonalities between thinkphp multi-file upload and php? Next I will introduce you... I have introduced a lot of topics for uploading multiple files directly in php, but I encountered multiple file uploads in thinkphp at the first time, so what are the differences and commonalities between thinkphp multi-file upload and php? Next I will introduce a Thinkphp framework for multifile Upload. I hope it will be helpful to you.
The description of multifile upload in the Thinkphp manual is clear: to use multiple files, you only need to modify the form
Change
Or
Currently, you have two Upload form fields, one for uploading images and one for uploading videos. The field names are image and video.
The html code is as follows:
Image:Video:
Model Code:
SaveRule = time; $ upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'Zip', 'flv '); $ upload-> thumb = true; // specifies the video path... Only the flv suffix is supported, $ upload-> videopath = '. /Public/upload/Video/'; $ upload-> savePath = '. /Public/upload/images/'; $ upload-> thumbPrefix = '2017 _ 250 _, 150_110 _, 1__156 _'; $ upload-> thumbMaxWidth = '2016 '; $ upload-> thumbMaxHeight = '000000'; if (! In_array ('', $ var) |! In_array ('', $ _ FILES ['video'] ['name']) {if (! $ Upload-> upload () {echo $ upload-> getErrorMsg (); die;} else {$ this-> info = $ upload-> getUploadFileInfo (); if (! In_array ('', $ var) & amp ;! In_array ('', $ _ FILES ['video'] ['name']) {return $ this-> info [1] ['savename'];} elseif (! In_array ('', $ var) {return $ this-> info [0] ['savename'];} else {return false ;}}} else {return flase ;}}// upload the video protected function videoupload () {if (! In_array ('', $ var) & amp ;! In_array ('', $ _ FILES ['video'] ['name']) {return $ this-> info [0] ['savename'];} elseif (! In_array ('', $ _ FILES ['video'] ['name']) {return $ this-> info [1] ['savename'];} else {return false ;}}?>
At the end of this article, I will analyze the multifile Upload principle. let's take a look at the html code.
This is to define the form variable as an array. in php, the array special variable can store multiple indefinite content, so we can customize the multifile Upload box, the following is an example of how to operate php.
Protected $ _ auto = array ('image', 'upload', 3, callback), // method of automatic completion array ('video', 'videoupload', 3, callback), // automatic completion method); // automatically fills in the uploaded image to generate a thumbnail
This tells thinkphp that it is an array variable and does not need to determine the length of the traversal array and then upload the code one by one, because thinkphp is ready.
Address:
Reprinted at will, but please attach the article address :-)