This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to upload multiple files in PHP.
Upload Multiple Files
In order to upload multiple files, you can use the move_uploaded_file()
method.
<html>
<body>
<form method='post' action='' enctype='multipart/form-data'>
<!-- Input of type multiple files -->
<input type="file" name="file[]" id="file" multiple>
<!-- Upload button -->
<input type='submit' name='submit' value='Upload'>
</form>
<?php
// Path to store uploaded file
$path = "C:/xampp/htdocs/";
// If the submit button is pressed
if(isset($_POST['submit'])){
// Count total files
$fileCount = count($_FILES['file']['name']);
// Iterate through the files
for($i = 0; $i < $fileCount; $i++){
$file = $_FILES['file']['name'][$i];
// Upload file to $path
move_uploaded_file($_FILES['file']['tmp_name'][$i], $file);
}
}
?>
</body>
</html>
Note: The move_uploaded_file()
method functions by moving an uploaded file into a new location.
The post How to Upload Multiple Files in PHP appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-03-06T04:49:57+00:00) How to Upload Multiple Files in PHP. Retrieved from https://www.scien.cx/2021/03/06/how-to-upload-multiple-files-in-php/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.