无法在Laravel的数据库中保存.png ext

时间:2019-04-24 17:49:56

标签: php mysql laravel

对不起,我无法使用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>

1 个答案:

答案 0 :(得分:0)

使用

$file->save(public_path('Admin/BusinessCards/'.$filename));

代替它

Image::make($file)->save(public_path('Admin/BusinessCards/'.$filename));