![](/img/trans.png)
[英]CodeIgniter 3 - Callable Form Validation by Config file not working
[英]Codeigniter form validation for file
我正在为我的项目使用codeigniter,我需要读取文件的内容。 所以,我需要验证来检查文件是否被选中。
这是我在控制器中的代码
$this->form_validation->set_rules(
'estimation_file',
'Project Estimation File',
'required'
);
但是,在选择文件时,它会显示错误信息-必须输入“项目估算文件”字段
在codeigniter中,您无法使用form_validation检查二维数组或文件字段的有效性,而是可以在发布数据后进行检查。
$this->form_validation->set_rules('validation_check','any required field','required');
if($this->form_validation->run()==FALSE)
{
// your code before posting...
}
else
{
// check the file posting
if($_FILES['estimation_file']['name']!='')
{
// if file selected or not empty
}
else
{
// if file not selected | empty | redirect
}
}
不要忘记在form字段中编写enctype =“ multipart / form-data”,否则您的文件字段将不会传递二维数组的值。
<form method="post" enctype="multipart/form-data" name="upload_form" action="">
<input type="hidden" name="validation_check" value="TRUE" />
<input type="file" name="estimation_file" value="" />
<input type="submit" value="Post" />
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.