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:
---------------------------------------------------------------------
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. , name= "upload_file[" must be named as 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.
The above describes the php file upload function-multi-file upload, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.