This section mainly introduces the multi-file upload function of php upload file. As long as you name the file upload tag in the form as an array, you can upload multiple files simultaneously.
Let's look at an example:
---------------------------------------------------------------------
<form enctype= "Multipart/form-data" action= "<?=$_server[' php_self ']?>" method= "POST" > <input type= " Hidden "name=" max_file_size "value=" 104857600 "/> <table> <tr> <td> upload file: <inpu T name= "upload_file[" "type=" File "size="/></td> </tr> <tr> <td> upload File: <input name= "upload_file[" "type=" File "size=" "/></td> </tr> <tr> & lt;td> upload file: <input name= "upload_file[" "type=" File "size="/></td> </tr> <tr> <td> upload file: <input name= "upload_file[" "type=" File "size=" "/></td> </tr> & Lt;tr> <td><input type= "Submit" name= "submit" value= "Upload"/></td> </tr> < /table></form><?php function Upload ($file _error, $file _tmp_name, $file _name) {$info = ""; if ($file _name = = "")return $info; Switch ($file _error) {case upload_err_ini_size: $info = $file _name. ": The file size exceeds the server limit"; Break Case upload_err_form_size: $info = $file _name. ": The file size exceeds the browser limit"; Break Case upload_err_partial: $info = $file _name. ": Only part of the file was uploaded"; Break Case Upload_err_no_file: $info = $file _name. ": No files were uploaded"; Break Case Upload_err_no_tmp_dir: $info = $file _name. ": Unable to find temp folder"; Break Case Upload_err_cant_write: $info = $file _name. ": File write Failed"; Break Case UPLOAD_ERR_OK: $upload _dir = './'. Iconv ("UTF-8", "gb2312", $file _name); if (file_exists ($upload _dir)) {$info = $file _name. ": File with the same name already exists"; }else{if (Move_uploaded_file ($file _tmp_name, $upload _dir)) { $info = $file _name. ": File upload succeeded"; }else{$info = $file _name. ": File upload Failed"; }} break; } return $info; } if (Isset ($_post[' submit ')) {$info = '; $count = count ($_files[' upload_file ' [' name ']); for ($i =0; $i < $count; + + $i) {if ($_files[' upload_file ' [' name '] [$i] = = "") continue; $info = Upload ($_files[' upload_file '] [' ERROR '] [$i], $_files[' upload_file ' [' tmp_name '] [$i ], $_files[' upload_file ' [' name '] [$i]); } Echo $info; }?>
--------------------------------------------------------------------------------------
The code execution results are as follows:
Attention:
1, <input name= "upload_file[" "type=" File "size=" "/>", name= "upload_file[" must be named in an array, or there will be an error: " Uninitialized string offset:0 ", which means that your array key value crosses the line
2, $_files[' upload_file ' [' name '] [$i], Upload_file is the name of the upload file marker in the form, and when multiple files are uploaded, the bidding clubs of $_files in the third dimension of the array is automatically numbered starting from 0.
Related recommendations:
PHP File upload function for code sharing
Configure PHP.ini to implement PHP file upload function
How to configure PHP.ini to implement PHP file upload function