The description of multifile upload in the Thinkphp manual is clear: to use multiple files, you only need to modify the form.
The description of multifile upload in the Thinkphp manual is clear: to use multiple files, you only need to modify the form
Change
Or
In this way, you can upload multiple files. yes, but there is a problem. Each upload form field corresponds to a database field. Of course, the uploaded files must be stored in the database. This writing method on the manual won't work. The Upload method is written in the model and completed automatically. However, the name of the form field is a name. in this way, only one value is returned for all the three form fields during the upload. So I thought of a method, but I always feel that there will be a better way to solve this problem. The search engine is searched, and there is no effect I want. You can only write it by yourself.
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:
- Protected $ info = '';
-
- Protected $ _ auto = array (
- Array ('image', 'upload', 3, callback), // automatic completion method
- Array ('video', 'videoupload', 3, callback), // automatic completion method
- ); // Automatically fill in the uploaded image to generate a thumbnail
- Protected function upload (){
- $ Var = $ _ FILES ['image'] ['name'];
- Import ('org. Net. uploadfile ');
- $ Upload = new UploadFile ();
- $ Upload-> 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 = '000000 ';
- $ 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 )&&! 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 a video
- Protected function videoupload (){
- If (! In_array ('', $ var )&&! In_array ('', $ _ FILES ['video'] ['name']) {
- Return $ this-> info [0] ['savename'];
- } Elseif (! In_array ('', $ _ FILES ['video'] ['name']) {
- Return $ this-> info [1] ['savename'];
- } Else {
- Return false;
- }
-
- }
From beginning to end, I felt that there was a very simple solution, but I couldn't find the solution. This is also a stubborn solution. If you have encountered this problem, contact Songlin. Pine forest is eager to solve this problem simply. Baidu, google, and bing have not found any problems.