The example of this article tells the thinkphp upload implementation method, share to everyone for reference. The implementation methods are as follows:
thinkphp Manual for multiple file upload description is clear: If you need to use more than one file, only need to modify the form, the
Copy Code code as follows:
<input type= ' file ' name= ' photo ' >
To
Copy Code code as follows:
<li><input type= ' file ' name= ' photo1 ' ></li>
<li><input type= ' file ' name= ' Photo2 ' ></li>
<li><input type= ' file ' name= ' Photo3 ' ></li>
Or
Copy Code code as follows:
<li><input type= ' file ' name= ' photo[] ' ></li>
<li><input type= ' file ' name= ' photo[] ' ></li>
<li><input type= ' file ' name= ' photo[] ' ></li>
For the moment, upload your own form field for two, one upload picture, one upload video. Field name is image, video.
The HTML code is as follows
Copy Code code as follows:
Photo: <input type= "file" Name= "image[]" >
Video: <input type= "file" Name= "video[]" >
Model Code:
Copy Code code as follows:
protected $info = ';
Protected $_auto = Array (
Array (' image ', ' upload ', 3,callback),//Automatic completion method
Array (' video ', ' Videoupload ', 3,callback),//Automatic completion method
)//Automatically populate upload image to generate thumbnails
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;
Video path ... Only FLV suffixes are supported,
$upload->videopath = './public/upload/video/';
$upload->savepath = './public/upload/images/';
$upload->thumbprefix = ' 250_115_,150_110_,213_156_ ';
$upload->thumbmaxwidth= ' 250,150,213 ';
$upload->thumbmaxheight= ' 115,110,156 ';
if (!in_array (', $var) | |!in_array (', $_files[' video '] [' name '])} {
if (! $upload->upload ()) {
echo $upload->geterrormsg ();d ie;
}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 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 the article I will analyze the principle of multiple file upload, first look at the HTML code
Copy Code code as follows:
<li><input type= ' file ' name= ' photo[] ' ></li>
<li><input type= ' file ' name= ' photo[] ' ></li>
<li><input type= ' file ' name= ' photo[] ' ></li>
This is to define the form variable as an array, in PHP, the special variable can store a number of indefinite long content, so we can customize the multiple file upload box, then in the PHP processing how we want to operate, see the example below.
Copy Code code as follows:
Protected $_auto = Array (
Array (' image ', ' upload ', 3,callback),//Automatic completion method
Array (' video ', ' Videoupload ', 3,callback),//Automatic completion method
)//Automatically populate upload image to generate thumbnails
This is to tell thinkphp is an array variable, does not need to be like the original eco-PHP to judge all the time to enumerate the group leader and upload the code, because the thinkphp has been done.
I hope this article will be helpful to everyone's thinkphp framework program design.