Is there a way to input a folder path for uploading files in PHP similar to using <input type="file" name="file"> for single files?
When uploading multiple files in PHP, you can use an array-like notation in the input field name to handle multiple files. By using <input type="file" name="files[]">, you can allow users to select multiple files for upload. In the PHP code, you can access these files as an array in the $_FILES superglobal.
<form method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload">
</form>
<?php
if(isset($_FILES['files'])){
$files = $_FILES['files'];
foreach($files['name'] as $key => $name){
$tmp_name = $files['tmp_name'][$key];
$destination = 'upload/' . $name;
move_uploaded_file($tmp_name, $destination);
}
}
?>
Keywords
Related Questions
- What is the correct syntax for selecting the last 10 entries from a MySQL table in PHP?
- What is the difference between null and 0 when counting empty lines in PHP?
- What are the best practices for securely storing database credentials in PHP scripts, especially when dealing with sensitive information like passwords?