Multiple File Upload in HTML and PHP with HTTP POST
When dealing with form submissions, we often encounter the need to handle multiple file uploads. In HTML5, it's possible to use a single file input control to select multiple files at once.
HTML:
<form method="post" enctype="multipart/form-data"> <input type="file" name="my_file[]" multiple> <input type="submit" value="Upload"> </form>
PHP:
$myFile = $_FILES['my_file']; $fileCount = count($myFile["name"]); for ($i = 0; $i < $fileCount; $i++) { echo "File #" . ($i+1) . ":\n"; echo " Name: " . $myFile["name"][$i] . "\n"; echo " Temporary file: " . $myFile["tmp_name"][$i] . "\n"; echo " Type: " . $myFile["type"][$i] . "\n"; echo " Size: " . $myFile["size"][$i] . "\n"; echo " Error: " . $myFile["error"][$i] . "\n"; }
Results:
When you select multiple files and click the "Upload" button, the specified PHP code will be executed and output information about each uploaded file, including its name, temporary file path, type, size, and any potential errors encountered.
Note:
This example demonstrates the basic implementation of multiple file uploads. For a secure and fully functional solution, refer to the PHP Manual: Handling file uploads for more detailed guidance on handling file uploads appropriately.
The above is the detailed content of How to Implement Multiple File Uploads in HTML and PHP using HTTP POST?. For more information, please follow other related articles on the PHP Chinese website!