Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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从另一个函数中的私有函数返回FALSE_Php_Function_Codeigniter - Fatal编程技术网

php从另一个函数中的私有函数返回FALSE

php从另一个函数中的私有函数返回FALSE,php,function,codeigniter,Php,Function,Codeigniter,在我的Codeigniter控制器中,有以下验证文件上传的私有函数 private function avatar_file_validation() { $config['upload_path'] = './uploads/avatars/'; $config['allowed_types'] = 'jpg|png'; $config['overwrite'] = TRUE; //overwrite user avatar

在我的Codeigniter控制器中,有以下验证文件上传的私有函数

     private function avatar_file_validation()
     {
        $config['upload_path'] = './uploads/avatars/';
        $config['allowed_types'] = 'jpg|png';
        $config['overwrite'] = TRUE; //overwrite user avatar
        $config['max_size'] = '800'; //in KB

        $this->load->library('upload', $config);

        if (! $this->upload->do_upload('avatar_upload'))
        {
            $error_data = array('error' => $this->upload->display_errors());

            $this->avatar_view($error_data); //loads view

            return FALSE;
        }

     }
如果上传时发生错误,我想停止此功能继续

function upload_avatar()
{

    //some code

    if($_FILES['entry_upload']['error'] !== 4) //if file added to file field
    {
        $this->avatar_file_validation(); //if returns FALSE stop code
    }

    //code continues: adds data to database, redirects

}

但是,即使返回false,该函数仍将继续。它只在我在一个函数中使用整个代码时有效,但我需要将它们分开,因为我将在多个函数中使用上载验证。我做错了什么?

表达式
返回FALSE仅适用于函数
avatar\u file\u validation()
。如果您想在上传失败时停止
upload\u avatar()
中的代码,您应该检查
avatar\u file\u validation()
的输出,如果它等于
FALSE
,也可以从该函数返回

例如:

function upload_avatar()
{
    //some code

    if($_FILES['entry_upload']['error'] !== 4) //if file added to file field
    {
        if(!$this->avatar_file_validation()) //if returns FALSE stop code
            return FALSE;
    }

    //code continues: adds data to database, redirects
}

表达式
返回FALSE仅适用于函数
avatar\u file\u validation()
。如果您想在上传失败时停止
upload\u avatar()
中的代码,您应该检查
avatar\u file\u validation()
的输出,如果它等于
FALSE
,也可以从该函数返回

例如:

function upload_avatar()
{
    //some code

    if($_FILES['entry_upload']['error'] !== 4) //if file added to file field
    {
        if(!$this->avatar_file_validation()) //if returns FALSE stop code
            return FALSE;
    }

    //code continues: adds data to database, redirects
}

使用返回语句?返回$this->avatar\u file\u validation()。它将停止函数的执行。是否使用return语句?返回$this->avatar\u file\u validation()。它将停止函数的执行