I want to upload multiple files and get the name of file to be upload:
I have for a type_demand some type_file to be uploaded
E.g : for type_demand A i can upload type_file X, Y, Z
In my php i want to get the 3 files and know what is the X, the Y and the Z.
here an example of my form:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post"
enctype="multipart/form-data">
<label for="type">Files to upload:</label>
<div class="form-group row">
<label for="FormControlFile1" class="col-sm-2 col-form-label">X</label>
<input type="file" class="form-control-file col-sm-10" id="FormControlFile1" name="myfile[]">
</div>
<div class="form-group row">
<label for="FormControlFile2" class="col-sm-2 col-form-label">Y</label>
<input type="file" class="form-control-file col-sm-10" id="FormControlFile2" name="myfile[]">
</div>
<div class="form-group row">
<label for="FormControlFile3" class="col-sm-2 col-form-label">Z</label>
<input type="file" class="form-control-file col-sm-10" id="FormControlFile3" name="myfile[]">
</div>
</div>
<button type="submit" class="btn btn-primary" name="upload">Upload</button>
</form>
and this is my php code:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_FILES['myfile'])){
$tmp_arr= $_FILES['myfile'];
}
// Create an array with desired structure.
for($i=0; $i<count($tmp_arr['name']); $i++){
$files[] = array(
'name' => $tmp_arr['name'][$i],
'type' => $tmp_arr['type'][$i],
'tmpName' => $tmp_arr['tmp_name'][$i],
'error' => $tmp_arr['error'][$i],
'size' => $tmp_arr['size'][$i],
//i want to have another information here to know if it's X, Y or Z file
);
}
foreach($files as $file){
echo '<br/>'.$file['name'] .' is for :' ;
}
as result i want to have for example:
NameOfFile1 is for: X
NameOfFile2 is for: Y
NameOfFile3 is for: Z
Thank you