Kohana Framework upload file Validation Rule Writing example _php instance

Source: Internet
Author: User
Tags kohana

First of all, I'm using the ko3.2.0 version.

Kohana's verification, the use of the students are less understand points, because each function of the annotation will give an example. Today, the situation is to verify the image upload, kohana example is the case.

Copy Code code as follows:
$array->rule (' file ', ' Upload::type ', array (' jpg ', ' png ', ' gif '));

This itself is not a problem, but it is always a bit inconvenient in the actual application, why, because upload to the back of the processing, not only to verify the upload of the picture and to verify the form of some fields.
We usually write that.
Copy Code code as follows:

$post = new Validation ($_post);
$file = new Validation ($_files);

This is not a problem to write, the verification of the time by the example to write OK. But feel new2 times a bit strange, and we also know that $_post and $_files are arrays, can one test it? That's for sure, of course, we'll have to turn them into a large array. It's OK to write this.
Copy Code code as follows:

$post = new Validation (Array_merge ($_post,$_files)); The classmate who does not understand, degrees Niang under Array_merge

Focus on the show. Verify that the field of the form form is not different from the one before the merge, and the key is how to write this image (or upload).
Well, the time relationship directly on the code, we can take to direct use, of course, interested students can also try rules.
Copy Code code as follows:

$post->rule (' img ', ' not_empty ')
->rule (' img ', ' Upload::type ', Array (': Value ', array (' jpg ', ' png ', ' gif '))
->rule (' img ', ' upload::size ', Array (': Value ', ' 1M '));

Ps:img is the name of the control named "File" in the form of the foreground form, and the ID is not found in the background.
Again, I use the kohana3.2.0 version, the other version of attention to modify the wording.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.