Is it possible to implement a mass image upload feature using PHP?
To implement a mass image upload feature using PHP, you can create a form with input type="file" set to accept multiple files. Then, use PHP to loop through the uploaded files and move them to a designated folder on the server. You can also validate the file types and sizes before moving them.
<?php
if(isset($_POST['submit'])){
$uploadFolder = 'uploads/';
foreach($_FILES['images']['tmp_name'] as $key => $tmp_name){
$file_name = $_FILES['images']['name'][$key];
$file_size = $_FILES['images']['size'][$key];
$file_tmp = $_FILES['images']['tmp_name'][$key];
$allowed_extensions = array('jpg', 'jpeg', 'png');
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
if(in_array($file_extension, $allowed_extensions) && $file_size < 2097152){
move_uploaded_file($file_tmp, $uploadFolder.$file_name);
echo 'File uploaded successfully: '.$file_name.'<br>';
} else {
echo 'Invalid file: '.$file_name.'<br>';
}
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="images[]" multiple>
<input type="submit" name="submit" value="Upload">
</form>
Keywords
Related Questions
- What are the potential pitfalls of transferring a database from one server to another using PHP?
- What are the security implications of implementing automatic session expiration based on user activity in PHP?
- Is there a recommended method for integrating a pre-built RSS parser like MagpieRSS into a website using PHP?