图片上传不起作用 laravel 5.4 没有出现任何错误

Asl*_*lam 2 php laravel

我不知道我在哪里做错了,文件未上传,名称未存储在数据库中。

这是我的控制器

      if(Input::hasFile('photo')) {
        $fotoName = 'peg' . $employee->id . '.' .
        $request->file('photo')->getClientOriginalExtension();
        $request->file('photo')->move(
        base_path() . '/public/images/employee/', $fotoName
        );
        $img = Image::make(base_path() . '/public/images/employee/' . $fotoName);
        $img->resize(150, null, function ($constraint) {
          $constraint->aspectRatio();
        });
        $img->save();
        $employee_fotos = Karyawan::find($employee->id);
        $employee_fotos->photo = $fotoName;
        $employee_fotos->save();
      }
Run Code Online (Sandbox Code Playgroud)

意见

<form class="form-horizontal" role="form" action="{{ route("karyawan.store") }}" method="post" multiple>
        {{ csrf_field() }}
    <div class="row">
      <!-- left column -->
      <div class="col-md-3">
        <div class="text-center">
          <img src="//placehold.it/100" class="avatar img-circle" alt="avatar">
          <h6>Upload a different photo...</h6>

          <input type="file" name="photo" class="form-control" />
        </div>
      </div>
</form>
Run Code Online (Sandbox Code Playgroud)

我没有收到任何错误,如果我验证它总是得到请添加图像或确保文件扩展名 .jpg 等,确保我选择了正确的图像和扩展名

Eri*_*dal 5

添加enctype="multipart/form-data"到您的form标签:

<form class="form-horizontal" enctype="multipart/form-data" role="form" action="{{ route("karyawan.store") }}" method="post" multiple>
        {{ csrf_field() }}
    <div class="row">
      <!-- left column -->
      <div class="col-md-3">
        <div class="text-center">
          <img src="//placehold.it/100" class="avatar img-circle" alt="avatar">
          <h6>Upload a different photo...</h6>

          <input type="file" name="photo" class="form-control" />
        </div>
      </div>
</form>
Run Code Online (Sandbox Code Playgroud)