0
    $input = Input::all();
    $input['resim'] = Input::file('resim')->getClientOriginalName();

    $rules = array( 
        'resim'         => 'required|max:3000|image|mimes:jpg,gif,png',
    );

    $validation = Validator::make($input, $rules);

    if($validation->fails())
    {
        return View::make('theme-admin.slider_add')
            ->nest('message_area', 'theme-admin.error', array('message' => $validation->messages()->first()));
    }

    ...

The issue is, Input::file('resim')->getClientOriginalName(); throw exception when the image is not uploaded. (e.g when I directly click on submit button on HTML form)

However, required|max:3000|image|mimes:jpg,gif,png this rule does not work if I erase that line. Whether if I upload a valid image or not, it doesn't pass mimes:jpg,gif,png control.

How can I do this without relying on Input::file('resim')->getClientOriginalName();? I want required control to handle what's necessary.

4

2 回答 2

0
//Input has file with name attribute as 'resim'
$rules = array('resim' => 'required|max:3000|image|mimes:jpg,gif,png');

$validator = Validator::make(Input::all(), $rules);

if ($validator->fails())
{
    return Redirect::to('...')->withErrors($validator);
}

...
于 2013-06-14T13:53:58.170 回答
0

问题在于我要上传的图像。出于某种原因,我的一些 JPG 文件无法通过 mimetype 检查,而其他文件则可以。

他们都通过了getClientOriginalName()

于 2013-06-19T21:49:16.413 回答