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

Add note that only file rules can be used to validate files #7969

Merged
merged 4 commits into from
Oct 24, 2023

Conversation

dgvirtual
Copy link
Contributor

Also add explanation regarding rule uploaded, that it makes the file upload required.

@kenjis kenjis added the documentation Pull requests for documentation only label Sep 24, 2023
Comment on lines 1000 to 1001
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
from file from being processed during validation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get well "prevend all rules for the from file from being processed during validation."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

Suggested change
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
from file from being processed during validation.
Therefore, if you add any general rules, like ``permit_empy`` to file validation rules array or string,
the file validation will not work correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you set rules 'permit_empty|max_size[profile_img,1024]|mime_in[profile_img,image/jpeg]', you can uplood 3mb pdf's, and validation will pass.

Copy link
Contributor Author

@dgvirtual dgvirtual Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but I cannot believe I messed up my English that much... sorry.

Should be:

general rules, like permit_empy, to file validation rules array or string will prevent all rules for the file form field from being processed during validation (thus validating even invalid files).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permit_empty (or other general rules) checks $_POST array, and the field for the file upload does not exist, so the validation passes.
However, most rules do not permit empty, and $_POST has no field for it, so if set, the validation will fail.

I don't know how to explain it briefly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's complicated. I was also thinking about filing a bug report (it is not good that adding a stray rule disables the other rules), but now I suspect that it is more of a limitation of validation than a bug...

Comment on lines 1000 to 1001
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
from file from being processed during validation.
Copy link
Member

@kenjis kenjis Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

Suggested change
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
from file from being processed during validation.
Rules for General Use like ``permit_empty`` do not check the uploaded file (in the ``$_FILES`` superglobal),
therefore, adding these rules to file validation rules array or string will not yield the expected results.

@@ -992,3 +995,7 @@ is_image Yes Fails if the file cannot be determined to be
======================= ========== ============================================= ===================================================

The file validation rules apply for both single and multiple file uploads.

.. note:: Only rules specifically created for file validation (like the ones listed in the table above) can be used to validate files.
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
Copy link
Contributor

@sammyskills sammyskills Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A rule typo:

Suggested change
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
Therefore, adding any general rules, like ``permit_empty``, to file validation rules array or string will prevend all rules for the

@kenjis
Copy link
Member

kenjis commented Oct 5, 2023

/github/workspace/user_guide_src/source/libraries/validation.rst:977: ERROR: Malformed table.

Text in column margin in table line 6.

======================= ========== ============================================= ===================================================
Rule                    Parameter  Description                                   Example
======================= ========== ============================================= ===================================================
uploaded                Yes         Fails if the name of the parameter does not  ``uploaded[field_name]``
                                    match the name of any uploaded files.
                                    If you want the file upload to be optional (not required),
                                    do not define this rule.

max_size                Yes         Fails if the uploaded file named in the      ``max_size[field_name,2048]``
looking for now-outdated files... none found
                                    parameter is larger than the second
                                    parameter in kilobytes (kb). Or if the file
                                    is larger than allowed maximum size declared
                                    in php.ini config file -
                                    ``upload_max_filesize`` directive.
max_dims                Yes         Fails if the maximum width and height of an  ``max_dims[field_name,300,150]``
                                    uploaded image exceed values. The first
                                    parameter is the field name. The second is
                                    the width, and the third is the height. Will
                                    also fail if the file cannot be determined
                                    to be an image.
mime_in                 Yes         Fails if the file's mime type is not one     ``mime_in[field_name,image/png,image/jpeg]``
                                    listed in the parameters.
ext_in                  Yes         Fails if the file's extension is not one     ``ext_in[field_name,png,jpg,gif]``
                                    listed in the parameters.
is_image                Yes         Fails if the file cannot be determined to be ``is_image[field_name]``
                                    an image based on the mime type.
======================= ========== ============================================= ===================================================

https://github.com/codeigniter4/CodeIgniter4/actions/runs/6407584328/job/17394669739?pr=7969

@dgvirtual
Copy link
Contributor Author

Yep, see that now, will fix later today.

kenjis
kenjis previously approved these changes Oct 6, 2023
Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kenjis kenjis dismissed their stale review October 6, 2023 08:07

There is a typo.

@kenjis kenjis merged commit 6f81e6e into codeigniter4:develop Oct 24, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Pull requests for documentation only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants