在我的 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,该函数也会继续。它仅在我在 1 个函数中使用整个代码时才有效,但我需要将它们分开,因为我将在多个函数中使用上传验证。我在这里做错了什么?