0

I'm trying to upload multiple images in one request with Laravel. However, it only seems to be seeing one file regardless of the fact that my file input has multiple files attached.

Markup:

<input class="file-input" type="file" name="fileUpload" multiple>

Controller:

$this->validate($request, [
'fileUpload' => 'image|nullable',

 ...

foreach ($request->file('fileUpload') as $image) {
    dd('stop');
}
dd('fail');

In this case, it always returns "fail". However, if I try to just $request->file('fileUpload') it will return to me a single file, like so: a single file

1

2 Answers 2

2

Like multiple selects, if you want to send multiple values then you need to use the array syntax in your input’s name attribute. So it should be fileUpload[] instead of just fileUpload

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

Comments

1

Change the name of the input fileUpload to fileUpload[] :

<input class="file-input" type="file" name="fileUpload[]" multiple />

Also in the controller for validating multiple fields, change 'fileUpload' to 'fileUpload.*' :

$this->validate($request, [
                           'fileUpload.*' => 'image|nullable',

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.