Laravel:文件验证问题

时间:2013-12-13 16:50:04

标签: php validation file-upload laravel-3

我在使用Laravel 3验证文件时遇到问题。无论我尝试什么,验证器都会通过。所以上传一个不应该被允许的mp4工作..我知道我不是太遥远,但我无法弄明白。

以下是我的表格发布的功能的相关部分:

public function post_edit($id)
{
    $input = Input::all();
    $files = Input::file();

    $dev = new Dev();
    $upload = new Upload();

    $v_upload = Validator::make($files, $upload->rules);
    $v_dev = Validator::make($input, $dev->rules);
    if($v_dev->passes() && $v_upload->passes()) {
        //success

        $dev = Dev::find($id);
        //save input data to model then save...
        $dev->save();

        foreach($files as $key=>$file) {
            if($file['name'] != '') {
                $upload = new Upload;
                $upload->for = 'devs';
                $upload->for_id = $id;
                $upload->name = $file['name'];
                $upload->type = $file['type'];
                $upload->save();
                Input::upload($key, 'public/upload', 'd'.$id.'_'.$file['name']);
            }
        }

        $message = "Success!";

        return Redirect::to('/dev/'.$id)->with('message', $message);
    }
    else {
        //failure
        dd($v_upload);
    }
}

我的模特:

class Upload extends Eloquent
{
    public static $table = 'uploads';
    public static $timestamps = false;

    public $rules = array(
        'size' => 'max:102400',
        'type' => 'mimes:png,jpg,gif,tiff,zip,tgz,css,html,js,php,txt,mp3,psd,csv,xls,xlsx,ppt,doc,docx'
    );
}

此外,我的文件数组(Input::file())如下所示:

array(2) {
  ["upload1"]=>
  array(5) {
    ["name"]=>
    string(17) "facebook-logo.jpg"
    ["type"]=>
    string(10) "image/jpeg"
    ["tmp_name"]=>
    string(14) "/tmp/phpEGqXWT"
    ["error"]=>
    int(0)
    ["size"]=>
    int(12939)
  }
  ["upload2"]=>
  array(5) {
    ["name"]=>
    string(15) "mobile-icon.jpg"
    ["type"]=>
    string(10) "image/jpeg"
    ["tmp_name"]=>
    string(14) "/tmp/phpygDS1k"
    ["error"]=>
    int(0)
    ["size"]=>
    int(8570)
  }
}

0 个答案:

没有答案