php multiple file upload
Introduces the process of uploading a single file in PHP. But sometimes, for convenience, we need to meet the need to upload multiple files at the same time. The principle of multi-file upload is the same, but when processing data, the uploaded data needs to be specially processed.
单文件上传
Here is a simple upload page, and the form submits two files at the same time. We can submit content through this page.
Note:
1.Input type="file" name="file[]"Compared with before, an extra square bracket is added after file
2.Write 2 or more input type="file" name="file[]"
We use $_FILES to receive file information, print and view the array:
The array structure is as follows
array (size=1) 'file' => array (size=5) 'name' => array (size=2) //文件名 0 => string 'psu.jpg' (length=7) 1 => string 'qwe.jpg' (length=7) //文件mime类型 'type' => array (size=2) 0 => string 'image/jpeg' (length=10) 1 => string 'image/jpeg' (length=10) //缓存文件 'tmp_name' => array (size=2) 0 => string 'E:\wamp\tmp\phpF6D5.tmp' (length=23) 1 => string 'E:\wamp\tmp\phpF6F5.tmp' (length=23) //文件错误信息 'error' => array (size=2) 0 => int 0 1 => int 0 //文件大小 'size' => array (size=2) 0 => int 225824 1 => int 151651
We can see that the two files are stored in an array, and the key names are the same as the uploaded single file. Therefore, we need to use a for() loop to retrieve the required data from the two files respectively.
The data of two files are saved in $_FILES at the same time. We need to use a simple loop to read the information of a single file and move the file to the location we want to put.
For the detailed judgment process, see single file upload. Only basic judgment is made here, and there is no reminder about the file size and format.
Please judge the file size and format by yourself according to the business and provide error reminders.