i try to make dynamic form that allow user to upload file in order that each image has video and they should upload and their path save to database but when i want to get file in my controller and store them in array i saw when i upload one or two files that work but when i try to upload more than 3 or 4 files my array becomes empty and i cannot solve it , please help me to complete my project thank a lot .
this is my html form :
<form action="admin/mediaUpload" method="post" enctype="multipart/form-data" id="mediaUpload">
<table class="table table-bordered table-hover" id="tableAddRow">
<thead>
<tr>
<th>image</th>
<th>film</th>
<th style="width:10px"><span class="glyphicon glyphicon-plus addBtn" id="addBtn_0"></span></th>
</tr>
</thead>
<tbody>
<tr id="tr_0">
<td><input type="file" id="image_0" name="image-0" class="form-control"/></td>
<td><input type="file" id="video_0" name="video-0" class="form-control" /></td>
<td style="background-color: white;"><span class="glyphicon glyphicon-minus addBtnRemove" style="margin-top: 9px;" id="addBtnRemove_0"></span></td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" id="mediaSubmit" value="بارگذاری" class="btn btn-primary" style="float: right; width: 40%"/><br/><br/>
</form>
and this is my controller :
public function mediaUpload(uploadRequest $uploadRequest)
{
$data = $uploadRequest->all();
$numberId = $uploadRequest['numberId'];
$rowCount = $uploadRequest['rowCount'];
$imageArray = [];
$videoArray = [];
for($i = 0 ; $i<$rowCount - 1 ;$i++)
{
$imageArray[$i] = Input::file('image-'.$i);
}
for($i = 0 ; $i<$rowCount - 1 ;$i++)
{
$videoArray[$i] = Input::file('video-'.$i);
}
var_dump($imageArray);
var_dump($videoArray);
}
You can use array inside the inputs:
<tr id="tr_0">
<td><input type="file" id="image_0" name="image[]" class="form-control"/></td>
<td><input type="file" id="video_0" name="video[]" class="form-control" /></td>
</tr>
<tr id="tr_1">
<td><input type="file" id="image_1" name="image[]" class="form-control"/></td>
<td><input type="file" id="video_1" name="video[]" class="form-control" /></td>
</tr>
<tr id="tr_2">
<td><input type="file" id="image_2" name="image[]" class="form-control"/></td>
<td><input type="file" id="video_2" name="video[]" class="form-control" /></td>
</tr>
And then just loop the request property:
if (Input::hasFile('video')) {
foreach (Input::file('video') as $video) {
// do something...
}
}
The same for image