


Example of how to write verification rules for uploading files in the kohana framework, _PHP tutorial
Example of writing verification rules for uploading files in kohana framework,
First of all, let me state that I am using version ko3.2.0.
Students who use kohana have little understanding of the verification, because there are examples in the comments of each function. The situation I encountered today was to verify the upload of images, and the example of kohana looked like this.
There is no problem with this in itself, but it is always a bit inconvenient in actual applications. Why? Because when it is passed to later processing, not only the upload of the image must be verified, but also certain fields of the form must be verified.
Normally we would write like this
$post = new Validation($_POST);
$file = new Validation($_FILES);
There is nothing wrong with writing like this, and it is OK to write according to the example when verifying. But it feels a bit strange to use new twice, and we also know that $_POST and $_FILES are both arrays, can they be verified at once? Yes, of course, we have to First turn them into a large array. This is OK.
$post = new Validation(array_merge($_POST,$_FILES));//For students who don’t understand, download array_merge
The key point is here, dear friends. Everyone knows that the way to write the fields in the verification form is no different from before the merger. The key is how to write the image upload (or other upload).
Okay, time-related, I will go directly to the code, and you can use it directly. Of course, interested students can also try out the rules.
$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 with input type="file" in the front-end form. The ID cannot be found in the back-end.
Let me reiterate that I am using version kohana 3.2.0. For other versions, please be careful to modify the writing.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to upload files to 123 Cloud Disk? You can upload files to 123 Cloud Disk for storage, but most friends don’t know how to upload files to 123 Cloud Disk. Next is the picture and text of how to upload files to 123 Cloud Disk brought by the editor for players. Tutorial, interested users come and take a look! How to upload files on 123 Cloud Disk 1. First open 123 Cloud Disk and enter the main page, register or log in to the account; 2. Then enter the page as shown below, click the [Upload] button guided by the arrow; 3. Then the bottom will expand In the function bar window, click the [Select File] function; 4. Finally, select the file to be uploaded and wait patiently for the upload to complete.

Nut Cloud is an efficient file management tool dedicated to providing users with intelligent file saving and synchronization services. It has powerful data synchronization and backup functions to ensure that users' data is safe. A series of functions of Nut Cloud are designed to meet the needs of users in different scenarios and provide an excellent user experience. So how to upload files in the Nut Cloud app? This tutorial guide will give you a detailed introduction to the steps. I hope it can help everyone in need. How to upload files to Nut Cloud? 1. On the My Files page, click on My Nut Cloud to open it. 2. On the opened page, click the plus icon in the lower right corner. 3. In the options that pop up at the bottom, click Upload from SD card. 4. In the opened mobile phone storage, select the file.

How to handle upload file errors in PHP? In the actual web development process, file upload is a common functional requirement. However, when processing file uploads, various errors may occur, such as files exceeding size limits, file types not allowed, etc. This article will introduce how to handle errors in uploading files in PHP and provide specific code examples. File upload errors are usually divided into two broad categories: client-side errors and server-side errors. Client errors refer to problems that occur when users upload files, such as the uploaded file is too large, the file type is

With the continuous advancement of technology and the rapid development of the Internet, the demand for the development of high-performance applications is becoming stronger and stronger. In this context, developers are constantly looking for better frameworks and tools to improve application performance. Phalcon and Kohana are two popular PHP frameworks, both of which are considered good choices for high-performance application development. So, in the competition between Phalconvs and Kohana, which one is more suitable for high-performance application development? In the next article, we will delve into this issue

How to use Kohana framework with PHP? Kohana is a PHP framework based on MVC architecture, evolved from the original CodeIgniter framework. Its philosophy is simplicity, flexibility and elegance. The Kohana framework provides rich functionality and good reusability, making it the first choice for many PHP developers. So, how to use the Kohana framework? Here we briefly introduce how to install and use the Kohana framework. Installation First, we need to install it from Kohana official website

In today's Internet era, desktop applications have been slowly replaced by web applications. However, there are still many businesses and individuals who need to use desktop applications. So, when you choose a framework for building high-performance desktop applications, which framework should you choose? This article will explore Yii2 and Kohana, two frameworks to help you make better decisions. Yii2 and Kohana are both open source frameworks based on the PHP language. Yii2 is a high-performance web application development framework that provides comprehensive architecture and support

Form validation and error messages are important features in the Kohana framework. They can help us verify the validity of form data on the server side and provide friendly error messages to users. This article will explain how to use form validation and error messages in the Kohana framework. Define form validation rules in the controller The Kohana framework provides a powerful validation class Validation that can be used to verify the validity of form data. In the controller we can define form validation rules. For example, we have a

PHP form processing example: uploading files In website development, we often need to provide users with the function of uploading files, such as avatars, pictures, documents, etc. As a back-end language, PHP can easily implement the file upload function. In this article, we will implement the file upload function based on PHP. 1. Prerequisite knowledge Before starting, there are some basic PHP knowledge that must be mastered: Collecting form data: PHP can obtain form data through global variables such as $_POST and $_GET. File upload: PH
