Laravel:上传大视频文件后出现TokenMismatch异常

时间:2017-06-06 11:00:08

标签: php laravel nginx file-upload

我已经设置了php.ini(nginx)

  

upload_max_size = 100MB

     

post_max_size = 200mb

我试图将15mb视频上传到我的程序中。起初我得到了这个错误。

  

VerifyCsrfToken.php第68行中的TokenMismatchException:

所以我添加了' / lesson / store'在VerifyCSRFToken中间件例外。

这里是突出显示视频输入的短代码:

<div class="form-group">
        <label class="control-label col-sm-2" for="video">Video:</label>
        <div class="col-sm-10">       

            <input class="form-control" type="file" accept="video/*" name="video" id="video" required>

        </div>
     </div> 

以下是整个表单代码:

<form method="{{$method}}" action="{{url('')}}{{$action}}" class="form-horizontal"  runat="server"  enctype="multipart/form-data">

{{ csrf_field() }}

    <div class="form-group">
        <label class="control-label col-sm-2" for="title">Title:</label>
        <div class="col-sm-10">
          <input type="text" class="form-control" id="title" name="title"  placeholder="Enter title" required value="{{ $lesson->title or '' }}">
        </div>
     </div> 
     <div class="form-group">
        <label class="control-label col-sm-2" for="description">Description:</label>
        <div class="col-sm-10">
            <textarea class="form-control" id="description" name="description">{{ $lesson->description or '' }}</textarea>        
        </div>
     </div> 
     <div class="form-group">
        <label class="control-label col-sm-2" for="episode">Episode:</label>
        <div class="col-sm-10">
          <input type="number" class="form-control" id="episode" name="episode"  placeholder="" required value="{{ $lesson->episode or '' }}">
        </div>
     </div> 
     <div class="form-group">
        <label class="control-label col-sm-2" for="video">Video:</label>
        <div class="col-sm-10">

           @if( !empty( $lesson->video ) )
           <input class="form-control" type="file" accept="video/*" name="video" id="video">
           <div class="video">
            <video width="100%" style="height:200px" controls>
              <source src="{{url('uploads/courses/' . $lesson['course_id']. '/' . $lesson['video'])}}" type="video/mp4">      
            Your browser does not support the video tag.
            </video>
           </div>  
           @else
            <input class="form-control" type="file" accept="video/*" name="video" id="video" required>
           @endif
        </div>
     </div> 

     <div class="form-group">
        <label class="col-sm-2"></label>
        <div class="col-sm-10">
            <input type="submit" value="{{$button}}" class="btn btn-success">
            <a href="{{ url()->previous() }}" class="btn btn-danger">Cancel</a>
        </div>
     </div>


</form>

然后我尝试再次上传,我收到验证错误说:

  

视频字段是必需的

因为我的代码中有这个:

 $this->validate($request, [
   'video' => 'required|mimetypes:video/avi,video/mpeg,video/quicktime,video/mp4|max:40000'
      ]);

我真的不知道如何解决这个问题。

更新:我上传了5mb视频,我收到了此验证错误:

  

视频无法上传。

1 个答案:

答案 0 :(得分:0)

在for verify csrf令牌中添加隐藏的输入字段为

<input type="text" name="_token" hidden/>

{{ csrf_field() }}