2016-07-24 59 views
1

Im与Laravel 5的表单有问题。当我将enctype属性指定为'multipart/form-data'时,我收到一个令牌不匹配错误。如果它被删除,表单总是失败我的控制器中指定的验证。Laravel 5:上传多个文件和其他输入

HTML

<form class="lajax" action="{{ action('[email protected]') }}" method="POST"> 
        <div class="form-group"> 
         <label>Album Name</label> 
         <input type="text" name="name" class="form-control">             
        </div> 

        <div class="form-group"> 
         <label for="coverFile">Album Cover Image</label> 
         <input name="cover" type="file" id="coverFile"> 
         <p class="help-block">Example block-level help text here.</p> 
        </div> 

        <div class="form-group"> 
         <label for="albumFiles">Album Images</label> 
         <input type="file" name="photos[]" multiple> 
        </div> 

        <button type="submit" class="btn btn-primary">Create Album</button> 

        {{ csrf_field() }} 
       </form> 

控制器

public function store(Request $request) 
    { 

     //request input verification rules 
     $rules=[ 
      'name'=>'required', 
      'cover'=>'required|image', 
      'photos'=>'required|array', 
      'photos.*'=>'image' 
     ]; 

     //perform validation 
     $this->validate($request,$rules); 

     // blah blah 
    } 

具体而言,图像似乎是失败。

错误报告:封面不是图像,照片0不是图像,照片1不是图像.....等等。

请帮

回答

0

我发现了错误!它在我的php.ini文件中。我将3M的post_max_size改为1000M。有效。

0

变化:

<form class="lajax" action="{{ action('[email protected]') }}" method="POST"> 

要:

<form method="POST" action="{{ action('[email protected]') }}" accept-charset="UTF-8" enctype="multipart/form-data"> 

在你的控制器,你可以检查你的输入这样的:

$request->hasFile('file_input_name'); 

还要检查Laravel Collectiv e创建表格:https://laravelcollective.com/