Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files in array #136

Open
gieglas opened this issue Apr 3, 2021 · 2 comments
Open

files in array #136

gieglas opened this issue Apr 3, 2021 · 2 comments

Comments

@gieglas
Copy link

gieglas commented Apr 3, 2021

hi,

I am trying to validate files in an array, for example my HTML looks like this:

<input type="file" name="name[0][avatar]">
<input type="file" name="name[1][avatar]">
<input type="file" name="name[2][avatar]">

Note that the number of avatars is dynamic, the users can add as many avatars as the want.

I tried something like $validation = $validator->validate($_FILES, ['name.*.avatar' => 'required|uploaded_file|max:2M|mimes:jpeg,png']); but doesn't seem to work. Looks like if my file is in an array the way I display above, the uploaded_file validation doesn't seem to work, as if it cannot find the uploaded file.

Any ideas?

Note, i use Slim framework. At first i didnt think $_FILES worked with Slim, but it does.

@gieglas
Copy link
Author

gieglas commented Apr 3, 2021

Ok weird fact. I was breaking my head why this was happening, as I had previously done array validations like that with uploaded_files. .

Seems that if the array contains both files and other inputs (i.e. text) the uploaded_file validations dont work for some reason. Ok its a bit hard to explain but i'll try. The files are simply ignored

  1. This works fine
<input type="file" name="name[0][avatar]">
<input type="file" name="name[0][icon]">
  1. This DOES NOT work
<input type="file" name="name[0][avatar]">
<input type="text" name="name[0][username]">

EDIT:

Same thing seems to going on with mimes:pdf validations.

@lcdss
Copy link

lcdss commented Dec 14, 2021

I had this exactly problem yesterday, trying to validate an array with both files and text. At the end of the day, I decide to make two validations, one for the files and other for the text fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants