Laravel(mime?)视频扩展验证

时间:2014-06-16 14:33:19

标签: forms file-upload laravel mime-types validation

我正在创建一个视频上传器,但我似乎无法正确验证。

现在我得到的是:

形式:

{{ Form::open(array('url'=>'form-submit','files'=>true)) }}
{{ Form::file('videos[]', ['multiple' => true]) }}
{{ Form::submit('Upload video') }}
{{ Form::close() }}

路线:

Route::any('form-submit', function(){
$files = Input::file('videos');

foreach($files as $file) {
    $rules = array(
        'file' => 'required|mimes:video/x-flv,video/mp4,video/mp2t,video/3gpp,video/quicktime,video/x-msvideo,video/x-ms-wmv|max:200000'
    );
    $validator = \Validator::make(array('file'=> $file), $rules);
    if($validator->passes()){

        $id = Str::random(14);

        $destinationPath    = 'public/uploads/' . $id;
        $filename           = $file->getClientOriginalName();
        $mime_type          = $file->getMimeType();
        $extension          = $file->getClientOriginalExtension();
        $upload_success     = $file->move($destinationPath, $filename);
    } else {
        return Redirect::back()->with('error', 'Only videos are allowed to be uploaded.');
    }
}

return Redirect::back()->with('success', 'The videos have been uploaded.');
});

我做错了什么?

0 个答案:

没有答案