SameenaG's avatar

Laravel 5.2 multiple file validation problem

I was doing some multiple file validation. I have my html like so:

<html>
    <body>
        <form name="le_form" action="/ft" method="POST" enctype="multipart/form-data">
            {{csrf_field()}}
            <input type="file" multiple name="le_file[0][]"/> 
            <input type="file" multiple name="le_file[1][]"/>
            <input type="file" multiple name="le_file[2][]"/>
            <input type="submit">
        </form>
    </body>
</html>

This action calls to this method in my other controller:

 public function ft(Request $request) {
  $v = Validator::make($request->file('le_file'),array(
            '.*.*' => 'max:100|required', //max of 100kb
            ));
        if ($v->fails()) return $v->messages();
        return 'Success';
}

I'm not sure why but the validator doesn't seem to be picking up the files. Though I can get a returned uploaded file object when I return $request->file('le_file.0.0'); But for my validator, its like it can't get to the files, because it is always returning success. Any help with this is appreciated, thank you very much.

0 likes
1 reply
d3xt3r's avatar

The way you are creating the validator, all association is lost. Try, if you just need to validate the files,

$v = Validator::make(['le_file' => $request->file('le_file')],array(
        'le_file.*.*' => 'max:100|required', //max of 100kb
    ));

Tip: All the compiled rules can be viewed by $v->getRules()

Please or to participate in this conversation.