Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件的Codeigniter表单验证_Php_Codeigniter - Fatal编程技术网

Php 文件的Codeigniter表单验证

Php 文件的Codeigniter表单验证,php,codeigniter,Php,Codeigniter,我正在为我的项目使用codeigniter,我需要读取文件的内容。因此,我需要验证来检查文件是否被选中 这是我在控制器中的代码 $this->form_validation->set_rules( 'estimation_file', 'Project Estimation File', 'required' ); 但是当选择一个文件时,它显示了一个错误:项目 估计文件字段是必需的 在codeigniter中,您不能使用form_validation检查二维数组或文件字

我正在为我的项目使用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
   }
}
不要忘记在表单字段中写入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>

在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
   }
}
不要忘记在表单字段中写入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>