CodeIgniter - 表单验证和文件上传数据 [英] CodeIgniter - Form Validation and File Upload Data

查看:194
本文介绍了CodeIgniter - 表单验证和文件上传数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法来验证文件的大小与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);

(取自CI文档)


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);

(taken from CI docs)

这篇关于CodeIgniter - 表单验证和文件上传数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆