Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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,我正在尝试检查上载文件字段()是否为空,或者是否对图像上载字段进行了其他验证。在视图中I echo但是它说$upload\u error是未定义的变量。我的代码有什么问题,如何解决 这是我的控制器功能 function add_main_products(){ $this->form_validation->set_rules('product_name', 'Main Product Category', 'required');

我正在尝试检查上载文件字段(
)是否为空,或者是否对图像上载字段进行了其他验证。在视图中I echo
但是它说
$upload\u error
是未定义的变量。我的代码有什么问题,如何解决

这是我的控制器功能

function add_main_products(){
            $this->form_validation->set_rules('product_name', 'Main Product Category', 'required');


            if ($this->form_validation->run() == FALSE){
                $this->load->view('admin/admin_add_mainproduct');
            }
            else{

                $config['upload_path'] = 'application/views/uploads/';               
                $config['allowed_types'] = 'gif|jpg|png|jpeg';                
                $this->load->library('upload', $config);

                if (! $this->upload->do_upload('userfile')){
                    $error['upload_error'] = array('error' => $this->upload->display_errors());

                    $this->load->view('admin/admin_add_mainproduct', $error);

                    return FALSE;
                }

                $this->mod_products->add_main_product($this->upload->data());
                $data = array('upload_data' => $this->upload->data());
                $data['result']="Main Product Added Successfully";
                $this->load->view('admin/admin_add_mainproduct', $data);    
           }
     }

不确定我是否正确理解了您的问题,但您可以用相同的方式为文件输入设置规则:

$this->form_validation->set_rules('userfile', 'Image', 'required');

让我知道这是否有帮助

您是否将其放在了
$this->form_validation->set_rules('product_name'、'Main product Category'、'required')下面??