-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Issue With Validating Multiple File Uploads #15044
Comments
Wich version of laravel and php are you using(excatly)? I guess that you are on PHP7, since thats the most common one when this error occurs. |
I am but actually i just updated to php 7 on this machine. I was having the same issue on an older version of php. |
how do u display the error for this validation ? |
Ye there maybe something wrong here?
errors.validation-message
But i can see them when i use
|
old office documents are uploaded as Are you running on nginx? |
Im running apache. So what mine type do i need to add to my validation rule to get .xls files working and the older ones. |
maybe u can try to use |
I will try that, but any ideas why the field still throws the error |
for validation array error msg, still no sign of how exactly to display it https://laravel.com/docs/5.3/validation#validating-arrays which already have like a couple of issues which got closed for no reason and mostly to get the error u cant use |
Yeah i saw those issues closed thats why i decided to open this. |
@ctfo Because theres so many issues with uploading multiple files with a single input field. Do you think it could work if i dynamically add a single file input field for each upload using js and then validate each one individually ? Is that possible |
u can ofcourse do so but i have also came up with a solution for displaying the array errors #13779 (comment) |
as for why u r always getting the error for the upload even when its not required , maybe u can try with a single file and see if u r still getting the same or is it only related to the multi file, showing us the whole form code would be better. |
I tried with a single file input, it works this issue is only with multiple file upload |
r u on v5.2 or v5.3 ? if on latest downgrade to v5.2 and re-test |
Validation
Html
|
This issue was happening on 5.2 and is still happening on 5.3 after i upgraded |
mmmmm, try to make the validation manually https://laravel.com/docs/5.3/validation#manually-creating-validators and only add the attachment to the rules array and see if the error still display. |
We're discussing multiple issues here:
Symfony Request creates a
old office documents are uploaded as application/vnd.ms-office (.doc, .xls, .ppt, etc...) based on the server configurations, to validate for an xls extension symfony expects a application/vnd.ms-excel instead, that's why your xls files won't pass.
That's not related to multiple files in specific actually, it's related to array validation in general, which I think should be solved. I'm going to check also on how to solve the first matter with symfony returning a null and see how this can be dealt with in laravel. |
maybe u r right but i have |
That's in Laravel 5.2 yes, because |
is this documented somewhere ? EDIT: on another note, if the input is required, laravel will make this input = null if it doesn't have a value "anything that != false" so the validation stops the form which makes sense, but sometimes means that the input will only be present in the input array if and only if its != null "or falsy value" otherwise it will be ignored so again i don't know what exactly is |
Check https://laravel.com/docs/5.3/upgrade under Nullable Primitives, it doesn't cover this specific case though, just a general notice that null isn't considered a valid value anymore. |
|
So this is a known bug then, i assume its being looked into? Im not sure whether i should completely change the way i upload multiple files or wait for the fix...
So here i need to use the full mimetypes instead of mimes. So application/vnd.ms-excel instead of xls, Is that right?
What do you mean by this, is there a fix being released? or am i outputting the error messages wrong, if so how do i properly output it. thank you |
|
Looks good and it would solve this issue for me. thank you again for your help on this. |
@themsaid can u also update the docs on how to retrieve the array errors so everyone can party ? |
@KayTokyo u dont need to include the validation logic in ur controller https://gist.github.com/ctf0/bb137c135b6d9383184d4deec0b24d56 |
@ctf0 working on that. |
Hey i was 100% that "application/vnd.ms-office" had fixed the issue for me. But ive tested it again today and i can't seem to pass validation on any office files. Ive tried .doc and .xls. Can someone else check this for me pls Heres my validation once again
|
You need to use |
Is it possible to use mimetypes validation alongside mime validation? For example
Though this is returning the error.
If i remove mimes and just try the validation below i still get the error
|
So office files won't pass with this rule?
|
I just double checked to make sure and with those rules, office files don't pass validation. returning the error |
Oh weird, .xls actually passes validation but not .doc. Edit: Samples i used. From google. www.columbia.edu/~dj114/excel-examples.xls |
If i want to validate legacy and new Microsoft extensions i need to write them out fully like below. This will validate ppt/pptx, doc/docx, xls/xlsx.
https://en.wikipedia.org/wiki/List_of_Microsoft_Office_filename_extensions Now as much as its a pain to list those (not even included mimetypes which contain office macros/scripts). Along side this how do i add validation for mimes such as pdf/jpg/png. As its returning the error Edit: i decided to stick with just using mimetypes as i don't think you can use both mimetypes and mimes.
And because the error message when validating mimetypes is not descriptive ive added a custom error message.
|
You can write a custom validation rule to hide all this behind it, also to be able to use these rules anywhere else. |
Right, also has the fix the #15063 been released? |
I'm having a similar problem with the upload field being required when no file is present. In my case I have a form which consists of If the user fills in the
|
@timgavin u should have the photo rule as 'photo.*' => 'required_without_all:title,body|mimetypes:image/jpeg,image/png,image/gif', without the photo array one |
@ctfo Removing it makes no difference; still receiving the error. Plus, having |
if then u should put ur rules as 'photo' => 'required_without_all:title,body|array|mimetypes:image/jpeg,image/png,image/gif', however this is just another newly introduced issue with the array validation in the 5.3. maybe @themsaid can help |
@ctfo Actually, doing that breaks my custom validation messages.
returns my custom error message
But
returns
|
@themsaid Confirmed; working as expected. Thanks! :) |
Hi,
I have a single input field for multiple uploads.
I am trying to validate each file with the same set of rules.
I am having some issues with this, i hope someone could address.
Thank you.
The text was updated successfully, but these errors were encountered: