2017-10-10 106 views
0

這裏是我的問題,是我的代碼都可以,只是想顯示錯誤消息,當用戶上傳一個不允許的大小/類型的圖像,全部在控制器或我需要創建一個通過$ error變量的模型?:Codeigniter:函數之間返回的變量

public function upload_face1($file1, $id){ 
    $config['upload_path'] = '././assets/administrador/images/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_width'] = '470'; 
    $config['max_height'] = '276'; 

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

    if (!$this->upload->do_upload($file1)) { 
     $error = $this->upload->display_errors()); // The $error Variable that don't display in my view, I can't return it to the function editMetatags() to load the view from there 
     return $error; 
    } else { 
     $register = $this->mmetatags->catchFace1($id); 
     unlink('././assets/admin/images/'.$register->face1); 
     $file_info = $this->upload->data(); 
     $save = $file_info['file_name']; 
     $this->mmetatags->editFace1($id, $save); 
     return true; 
    } 
} 

public function editMetatags($d){ 
    $param["cod_meta"] = $d; 
    $param['title'] = $this->input->post("title"); 
    $param['description'] = $this->input->post("description"); 
    $param['keywords'] = $this->input->post("keywords"); 

    if (isset($_FILES['face1']) && $_FILES['face1']['name'] != ''){ 
     $file1 = $this->upload_face1('face1', $d); //The file is there, but It wasn't uploaded beacause don't have the allowed size or type. 
    } 

    $data['error'] = $error; // Here is the variable "returned" 
    $data['mensaje'] = 'success :D'; 
    $data["metatags"] = $this->mmetatags->loadMetatags($d); 
    $this->load->view('administrador/editmetatags', $data, $error); 

} 

謝謝反正。

回答

0

一個簡單的方法來獲得錯誤的觀點是使用CodeIgniter的負載::瓦爾()這樣的:

$this->load->vars(array('upload_errors' => $this->upload->display_errors())); 

然後在您的視圖:

if(isset($upload_errors)) 
     echo $upload_errors; 
+0

哇,謝謝你:D。 – raulmartiarena