0

I am trying to upload multiple files with a request validation but the validation rule is not applying correctly. I want only images to be validated. I set also the mime types but it is not working. What seems to be the problem?

I have tried putting 'fieldname.*' and set mimes but it is not working as expected it is blocking even images.

Here is my input field:

<input type="file" name="files[]" multiple>

My validation rule:

public function rules()
{
    return [
        'content' => 'nullable|string|max:3000',
            'files.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
    ];
}
2
  • Which framework is it?? Commented May 19, 2019 at 12:42
  • Im using Laravel Commented May 19, 2019 at 14:12

2 Answers 2

0

Change your rules function as below:

public function rules()
{
    return [
        'content' => 'nullable|string|max:3000',
        'files' => 'array|mimes:jpeg,png,jpg,gif,svg|max:2048'
    ];
}

Also, please make sure that your form have enctype="multipart/form-data" attribute as well.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello thank you. I have tried your solution but I get the same results. It is working well with single file. I have browse some answers the approach is the same and they are getting correct results. I don't quite understand yet what happened. I will further investigate. I have referenced my previous solution here stackoverflow.com/questions/45188174/…
0

Thank you for the answers. All of your answers are correct. I did restart my server and it solved the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.