我有表单,里面有文本字段、复选框、选择和文件上传。我需要的是仅上传图像并将图像的位置传递给 Controller ,以便我可以将它们保存到数据库。
这是我的 Controller :
public function spremi(){
$input= Request::all();
Oglas::create($input);
return redirect('other');
}
路线:
Route::post('other', 'OglasController@spremi');
<小时/>
如果我返回请求,或者为我的数据库创建“Oglas”,我得到的只是图像名称。并且图像没有上传到任何地方? (例如存储/..、公共(public)/...)。
{{Form::file('slike', ['class' => 'field']) }}
我的问题是:如何让事情以最好的方式工作,以便我的图像上传到一个文件夹,并且只有它们的正确位置保存在数据库中?
提前谢谢大家。
最佳答案
这是针对当时 1 个图像移动/上传进行测试的:
$image = $request->file('slike');
$destinationPathImg = '/your path/images/';
if (!$image->move($destinationPathImg, $image->getClientOriginalName())) {
return 'Error saving the file.';
}
您的表单需要具有多部分/表单数据:
{!! Form::open(['url'=>'/other','enctype'=>"multipart/form-data"]) !!}
关于php - Laravel 5多个图像上传到表单内并将img位置保存在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36449055/