Put*_*ari 7 php forms image-uploading laravel laravel-5.2
最后我可以上传和移动图像,但现在我想在Laravel上创建多个上传图像.那可能吗?我必须使用数组才能制作它吗?
我可以从这段代码中稍微修改一下吗?
它在我的ProductController.php上
$picture = '';
if ($request->hasFile('images')) {
$file = $request->file('images');
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$picture = date('His').$filename;
$destinationPath = base_path() . '\public\images/';
$request->file('images')->move($destinationPath, $picture);
}
if (!empty($product['images'])) {
$product['images'] = $picture;
} else {
unset($product['images']);
}
Run Code Online (Sandbox Code Playgroud)
谢谢.注意:我上面的代码来自stackoverflow上的一个善良的人,再次感谢;)
soh*_*man 14
在您的前端表单中,您必须使用您的字段属性名称
name="images[]"
Run Code Online (Sandbox Code Playgroud)
你的控制器代码就是这样的.
$picture = '';
if ($request->hasFile('images')) {
$files = $request->file('images');
foreach($files as $file){
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$picture = date('His').$filename;
$destinationPath = base_path() . '\public\images';
$file->move($destinationPath, $picture);
}
}
if (!empty($product['images'])) {
$product['images'] = $picture;
} else {
unset($product['images']);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14661 次 |
| 最近记录: |