Example of writing a file verification rule in the kohana framework, _ PHP Tutorial

Source: Internet
Author: User
Tags kohana
Example of writing a file Upload verification rule in the kohana framework ,. Example of writing a file verification rule in the kohana framework, first declare that I use the ko3.2.0 version. kohana verification is rarely understood by the students, because each function annotation will give an example of how the kohana framework uploads File verification rules,

Declare that I use ko3.2.0.

Kohana verification is rarely understood by the students, because every function annotation will give an example. Today, we are faced with the situation of verifying image uploading. the kohana example is like this.

The code is as follows:

$ Array-> rule ('file', 'Upload: type', array ('jpg ', 'PNG', 'GIF ')));


This is not a problem, but it is inconvenient in actual application. why, in addition to verifying the upload of images, you must also verify certain fields in the form.
Generally, we write

The code is as follows:


$ Post = new Validation ($ _ POST );
$ File = new Validation ($ _ FILES );


There is no problem in writing this way, and it is OK to write it as an example during verification. but I think new2 is a little strange, and we also know that $ _ POST and $ _ FILES are arrays. can we perform one verification? That's for sure. of course, we have to convert them into a large array first. in this case, OK.

The code is as follows:


$ Post = new Validation (array_merge ($ _ POST, $ _ FILES); // If you do not understand it, du Niang's array_merge


It's important to go out. you all know that there is no difference between the field writing method of the form and the pre-merger. The key is how to write this image upload (or other upload.
Okay, the time relationship is directly written into the code. you can use it directly. of course, you can also try rules if you are interested.

The 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 control name of input type = "file" in the front-end form. the ID cannot be found in the background.
Declare the kohana3.2.0 version I used again. For other versions, pay attention to the modification method.




Declare, first declare that I'm using ko3.2.0. kohana verification, and the students who use it are not familiar with it, because every function annotation will give an example...

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.