Kohana Framework upload file Validation rules example _php instance

Source: Internet
Author: User
Tags kohana
First of all, I'm using the ko3.2.0 version.

Kohana verification, with the students are less understanding, because each function of the comments will give an example. The situation today is to verify the image upload, the Kohana example is this way.
Copy CodeThe code is as follows: $array->rule (' file ', ' Upload::type ', array (' jpg ', ' png ', ' gif '));
This itself is not a problem, but, in the actual application is always a bit inconvenient, for what, because to the back of the processing, not only to verify the upload of the image to verify the form of some fields.
In general, we would write this.
Copy CodeThe code is as follows:
$post = new Validation ($_post);
$file = new Validation ($_files);
This writing is not a problem, the verification of the case by example is OK. But I think 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 have to turn them into a large array first.
Copy CodeThe code is as follows:
$post = new Validation (Array_merge ($_post,$_files));//Don't understand the classmate, degrees Niang under Array_merge
The focus is on the show, folks. Everyone knows there is no difference between validating the field of form form and merging it, the key is how to write this image (or other upload).
Well, the time relationship directly on the code, you can take to direct use, of course, interested students can also try the rules.
Copy CodeThe code is 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 foreground form form input type= "file" that control name, the background is not found ID.
Again, I use the kohana3.2.0 version, the other version of the note to change 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.