对不起,我无法使用laravel将png图像上传到数据库,但jpg成功上传,如果我删除验证,验证将不起作用,请先谢谢。
SQLSTATE [HY000]:常规错误:1364字段'businessimg'没有默认值
public function storefiles(Request $request)
{
$this->validate($request, [
'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:9048',
]);
$addfiles= new Files();
$addfiles->appo_id = $request->input('Appoid');
if($request->hasFile('file'))
{
$file = $request->file('file');
$filename = time().'.'.$file->getClientOriginalExtension();
Image::make($file)->save(public_path('Admin/BusinessCards/'.$filename));
$addfiles->businessimg = $filename;
}
$addfiles->save();
return redirect()->back();
}
我的HTML:
<form class="" action="{{url('storefiles')}}" role="form" enctype="multipart/form-data" method="POST">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="Appoid" value="{{$addfiles->id}}">
<label for="File">File :</label>
<input type="File" name="file">
<input class="btn btn-success btn-mini deleteRecord" type="submit" name="submit" value="Upload">
</form>
答案 0 :(得分:0)
使用
$file->save(public_path('Admin/BusinessCards/'.$filename));
代替它
Image::make($file)->save(public_path('Admin/BusinessCards/'.$filename));