Today we discuss about the php upload multiple files example.
Below are the steps to upload multiple files and store them in a folder −
HTML code
<form method="post" id="" action="action.php" enctype="multipart/form-data">
<div class="row" style="padding-top: 10px;">
<div class="col-md-6">
<div class="form-group">
<label>PDF/Image</label>
<input type="file" class="form-control" name="patient_report[]" multiple="multiple">
</div>
</div>
</div>
<div class="row" style="padding-top: 10px;">
<div class="col-md-6">
<button type="submit" class="btn btn-primary waves-effect waves-light">Submit</button>
</div>
</div>
</form>
Create action.php file and uploads folder
$file_name_array = array();
if(!empty($_FILES['patient_report']['name']['0'])){
for($i=0; $i<count($_FILES['patient_report']['name']); $i++){
if($_FILES['patient_report']['name'][$i]!=''){
move_uploaded_file($_FILES['patient_report']['tmp_name'][$i],'./uploads/'.$_FILES['patient_report']['name'][$i]);
$file_name_array[] =$_FILES['patient_report']['name'][$i];
}
}
}
echo '<pre>';
print_r($file_name_array);
echo '</pre>';
die('---');
Like us on Facebook and Linkedin for more updates.
Integrate MailChimp API with PHP