CodeIgniter - 表单验证和文件上传数据 [英] CodeIgniter - Form Validation and File Upload Data
问题描述
我想知道是否有一种方法来验证文件的大小与CodeIgniter 2.0中的表单验证类。我有一个包含文件输入的形式,我想这样做:
$ this-> form_validation-> set_rule('file','File','file_type [image / jpeg | image / gif | image / png] | file_max_size [500]');
我想过扩展验证类,使用上传类并根据上传数据进行验证,但这可能很耗时。
有人知道表单验证类的任何扩展,这个?
文件上传类实际上有自己的一套验证规则,可以这样设置
$ config ['upload_path'] ='./uploads/';
$ config ['allowed_types'] ='gif | jpg | png';
$ config ['max_size'] ='100';
$ config ['max_width'] ='1024';
$ config ['max_height'] ='768';
$ this-> load-> library('upload',$ config);
I was wondering if there's a way to validate a file's size with the form validation class in CodeIgniter 2.0. I have a form that contains a file input and I want to do something like this:
$this->form_validation->set_rule('file', 'File', 'file_type[image/jpeg|image/gif|image/png]|file_max_size[500]');
I thought about extending the validation class to combine it with the upload class and validate based on the upload data, but that might be time consuming.
Does anyone know of any extensions for the form validation class that would do something like this?
The File Upload Class actually has its own set of validation rules you can set like so
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
这篇关于CodeIgniter - 表单验证和文件上传数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!