在我的Codeigniter控制器中有以下私有函數驗證文件上傳。從另一個函數的私人函數返回FALSE
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函數中使用整個代碼,但我需要將它們分開,因爲我將在多個函數中使用上傳驗證。我在這裏做錯了什麼?
使用return語句?返回$ this-> avatar_file_validation()。它會停止執行該功能 – 2012-07-09 19:08:57