The following for everyone to bring a Thinkphp3.2 simple solution to upload a multi-file upload only one problem. Content is very good, now share to everyone, but also for everyone to make a reference.
HTML Simple page:
Index.html Code:
<form action= "{: U (' Index/upload ')}" method= "Post" enctype= "multipart/form-data" > File upload: <input type= "Files" Name = "test[" > File upload: <input type= "file" name = "test[]" > File upload: <input type= "file" name = "test[]" > File upload: < Input type= "file" name = "test[]" > File upload: <input type= "file" name = "test[]" > File upload: <input type= "file" name = "T est[] "> Upload: <input type=" file "name =" test[] "> File upload: <input type=" file "name =" test[] "> File upload: <input ty pe= "file" name = "test[]" > File upload: <input type= "file" name = "test[]" > File upload: <input type= "file" name = "test[" " ; File Upload: <input type= "file" name = "test[]" > <input type= "submit" value = "Submit" ></form>
Controller IndexController.class.php Code:
<?phpnamespace home\controller;use Think\controller;class Indexcontroller extends Controller {public Function index () { $this->display ();} public Function upload () { if (is_post) { $config = array ( ' maxSize ' = 3145728, ' rootpath ' = '/uploads/', ' savepath ' = ', ' savename ' = = Array (' Uniqid ', Mt_rand ( 1,999999). ' _ '. MD5 (Uniqid ())), ' exts ' = = Array (' jpg ', ' gif ', ' PNG ', ' jpeg '), ' autosub ' = "= True, ' SubName ' = = Array (' Date ', ' YMD '), ); $upload = new \think\upload ($config);//instantiation of upload class $info = $upload->upload (); if (! $info) { $this->error ($upload->geterror ()); } else{ foreach ($info as $file) { echo $file [' Savepath ']. $file [' Savename ']; } } else{ $this->display ();}}}
Upload Results display:
Many people in the multi-file upload, the last to find just upload a, mainly because of the name, because it is the same names, so the last picture left
Workaround: The first type:
$config = Array ( ' maxSize ' = = 3145728, ' rootpath ' = './uploads/', ' exts ' = = Array (' jpg ', ' GIF ', ' PNG ', ' jpeg '), ' autosub ' = True, ' subname ' = = Array (' Date ', ' YMD '), ' saverule ' = ', ' );
Empty $config inside the Saverule, after the name of the upload: 59c8d38cdb968.jpg
If you feel this name is unreliable, you can take a second approach:
$config = Array ( ' maxSize ' = = 3145728, ' rootpath ' = './uploads/', ' savename ' = = Array (' Uniqid ', Mt_rand (1,999999). ' _ '. MD5 (Uniqid ())), ' exts ' = = Array (' jpg ', ' gif ', ' PNG ', ' jpeg '), ' autosub ' = ' = True ' SubName ' = = Array (' Date ', ' YMD '), );
Set $config: ' savename ' = = Array (' Uniqid ', Mt_rand (1,999999). ' _ '. MD5 (Uniqid ())),
The final results are similar to: 672563_30ad4d8a2aafc832363de8edc1940b5c59c8d44a303f9.jpg
However, the name can be modified as needed, many file upload method, here is just a simple and convenient way!
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!