Thinkphp multifile Upload implementation method ,. Thinkphp multi-file Upload implementation method. This article describes the implementation method of Thinkphp multi-file upload for your reference. The implementation method is as follows,
This article describes how to implement Thinkphp multi-file upload. The specific implementation method is as follows:
The description of multifile upload in the Thinkphp manual is clear: to use multiple files, you only need to modify the form
The code is as follows:
Change
The code is as follows:
Or
The code is as follows:
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:
The code is as follows:
Image:
Video:
Model Code:
The code is as follows:
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;
}
}
At the end of this article, I will analyze the multifile Upload principle. let's take a look at the html code.
The code is as follows:
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.
The code is as follows:
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
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.
I hope this article will help you with ThinkPHP framework programming.
Example: This article describes how Thinkphp implements multifile Upload. The specific implementation method is as follows...