How can PHP be used to create a user-friendly file upload system that allows for bulk uploads without manual selection of each file?
To create a user-friendly file upload system that allows for bulk uploads without manual selection of each file, we can utilize the HTML multiple attribute in combination with PHP to handle the file uploads efficiently. By allowing users to select multiple files at once, we can streamline the upload process and improve the user experience.
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload Files">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['files'])) {
$uploadsDir = 'uploads/';
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
$file_name = $_FILES['files']['name'][$key];
$file_tmp = $_FILES['files']['tmp_name'][$key];
move_uploaded_file($file_tmp, $uploadsDir . $file_name);
}
echo 'Files uploaded successfully!';
}
?>