paklic9
151
2
Laravel

File validation

Posted 1 year ago by paklic9

I have problem with file validation. It doesnt validate. I am not sure, if I am doing it right, because I know, there is more similarly ways to do it. I wasnt using server side validation much, only at registration and in that i was using method validate(request(),[...]) and that works. Can you help me? How to validate the file.

My code:

    $files = $request->file('soubory');
    if($request->hasFile('soubory'))
    {
      foreach ($files as $file) {
        $rules = array('file' => 'required|mimes:png,gif,jpeg,txt,pdf,doc');
        $validator = \Validator::make(array('file'=> $file), $rules);
        if($validator->passes()){
        //upload file
        }
     }

Thanks in advance for help.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.