简体   繁体   English

Laravel 5.1:无法上传视频文件

[英]Laravel 5.1: can't upload a video file

On submitting a file I had this following error: 提交文件时,出现以下错误:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'video_ogg' cannot be null (SQL: insert into `profiles` (`about_me`, `video_ogg`, `updated_at`, `created_at`) values (lorem, , 2017-07-23 02:15:50, 2017-07-23 02:15:50))

which states that the field video_ogg cannot be null but when I verify on debugging mode this field is not empty (see below) 它指出字段video_ogg cannot be null但是当我在调试模式下验证时,该字段不为空(请参见下文)

controller 控制者

    public function store(Request $request)
   {
      // Validation //
      $validation = Validator::make($request->all(), [
         'about_me' => 'required',
         'video_ogg'    => 'required|mimes:mp4,ogx,oga,ogv,ogg,webm|min:1|max:3240',
      ]);

      // Check if it fails //
      if( $validation->fails() ){
         return redirect()->back()->withInput()
                          ->with('errors', $validation->errors() );
      }

      $profile = new Profile;

      //Debugging
      dd($request->files);

      // save media data into database //
      $profile->about_me = $request->input('about_me');
      $profile->video_ogg = $request->input('video_ogg');
      $profile->save();

      return redirect('/profile')->with('message','You just created your profile!');
   }

debugging result 调试结果

FileBag {#45 ▼
  #parameters: array:1 [▼
    "video_ogg" => UploadedFile {#30 ▼
      -test: false
      -originalName: "mov_bbb.ogg"
      -mimeType: "audio/ogg"
      -size: 614492
      -error: 0
    }
  ]
}

Here as you can see on debugging the video is uploaded or I mean is in the request array but I still have an error message. 正如您在调试时看到的那样,视频已上传,或者我的意思是在请求数组中,但我仍然收到错误消息。

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'video_ogg' cannot be null (SQL: insert into `profiles` (`about_me`, `video_ogg`, `updated_at`, `created_at`) values (lorem, , 2017-07-23 02:15:50, 2017-07-23 02:15:50))

view 视图

{!! Form::open(['url'=>'/profile', 'method'=>'POST', 'files'=>'true']) !!}
...
      <div class="form-group">
         <label for="video_ogg">Upload Video (ogg)</label>
         <input type="file" class="form-control" name="video_ogg">
      </div>
...

which output this 哪个输出

<form method="POST" action="http://localhost:8000/profile" accept-charset="UTF-8" enctype="multipart/form-data"><input name="_token" type="hidden" value="KxvK6tONoUhBCx58ESlbE1hh9eP8hy5nQyNqb62W">

So I did verify that enctype="multipart/form-data" is in the form. 因此,我确实确认了enctype="multipart/form-data"处于表单中。

model 模型

class Profile extends Model
{
    //
    protected $fillable = ['video_ogg', 'about_me'];
}

我猜你应该使用file方法而不是inputhttps : //laravel.com/docs/5.4/requests#files

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM