This article mainly introduces the relevant information on the PHP implementation of uploading multiple file sample codes. It has certain reference value. Interested friends can refer to it.
Upload multiple files
1. Before operating multi-file information, you need to build the file information, and use the buildInfo function to convert the three-dimensional array into a two-dimensional array that is convenient for file operations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
The judgment between single file and multiple files lies in the type of file array, single file (two-dimensional array), multiple files (three-dimensional array).
2. File upload function and parameters
Copy code The code is as follows:
function uploadFiles ($path = "uploads", $allowExt = array("jpg", "gif", "png", "wbmp"), $maxSize = 1048576, $imgFlag = true)
path , save the directory. allowExt, array of allowed extensions. maxSizeThe maximum upload file size. imgFlag, image file identifier.
3. Determine whether the directory where the file is saved exists
1 2 3 |
|
4. Pass in the constructed file information and save it to files
1 2 |
|
5. Determine the error type of the file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
6.Restrict the file type
1 2 3 4 5 |
|
7. Restrict whether the picture type is true
1 2 3 4 5 |
|
8. Determine the file size
1 2 3 |
|
9. Determine whether the file is uploaded through post
1 2 3 |
|
10. Rename the file (Unique and non-duplicate) and save to the target directory
1 2 3 4 5 6 7 8 9 |
|
Rewrite the name in the file information array, delete the variables file['error'] and file[ 'tmp_name']. Finally, save the successfully uploaded files to the uploadedFiles array.
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
In phpUpload multiple filesmax_file_uploads limit issue
Solution to the problem of Uploading multiple filesmax_file_uploads limitation in
########### Sample code for multiple images ###########################
The above is the detailed content of How to upload multiple files in PHP. For more information, please follow other related articles on the PHP Chinese website!