I have a form combination of text and image upload for multi-rows insertion to table
<input class="form-control" id="" placeholder="" type="text" name="failure[]">
<input class="form-control" id="" placeholder="" type="text" name="remark[]">
<input class="form-control" id="" placeholder="" type="hidden" name="id[]" value={{ $id }}>
<input type="file" accept="image/*" capture="camera" name="image[]" />
<input class="form-control" id="" placeholder="" type="text" name="failure[]">
<input class="form-control" id="" placeholder="" type="text" name="remark[]">
<input class="form-control" id="" placeholder="" type="hidden" name="id[]" value={{ $id }}>
<input type="file" accept="image/*" capture="camera" name="image[]" />
<input class="form-control" id="" placeholder="" type="text" name="failure[]">
<input class="form-control" id="" placeholder="" type="text" name="remark[]">
<input class="form-control" id="" placeholder="" type="hidden" name="id[]" value={{ $id }}>
<input type="file" accept="image/*" capture="camera" name="image[]" />
id in the hidden are unique as there are generated by a loop.. above just for illustration purpose. original code are too complicated to be posted here
in controller I am trying to get the image correspond to each set of row
public function checklist_store_data(Request $request)
{
$input = Input::all();
return $input; // parse form data received
}
If I decided to upload one photo and leave other 2 empty this is what I get from the console.log
{"failure":["A","B","C"],"remark":["X","Y","Z"],"id":["1","2","3"],"image":[{}]}
Questions
How can I correspond the image files uploaded to the respected id ?
How can I get the file name of the image for the image object ?
Thanks in advance Apologize if I unable to explain my problem clearly and thanks for your patience
答案 0 :(得分:0)
首先,您的表单元素应具有用于多部分数据的'enctype'属性:
<form action="your_action", method="post", enctype = "multipart/form-data">
用于检查图像数组中的文件:
dd($request->image);