2013-10-03 58 views
3

我想顯示對重定向link.here內容插件的成功消息的錯誤消息是我的控制器代碼: -笨 - 如何顯示從do_upload

public function do_upload($field) { 
     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $config['max_size'] = '100000'; 
     $config['max_width'] = '3000'; 
     $config['max_height'] = '3000'; 

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

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

      return $error; 
     } else { 

      $updata =$this->upload->data(); 
      $data = $updata['raw_name'].$updata['file_ext']; 
      return $data; 
     } 


    } 


public function index() { 

$this->load->model('blog'); 

     if(isset($_POST['post']) && (!empty($_POST['post']) || strlen($_FILES['inputUpProfile']['name']) > 0)){ 
     if(strlen($_FILES['inputUpProfile']['name']) > 0) 
     { 
     $pic = $this->do_upload('inputUpProfile'); 
     print_r($pic); 
     if ($this->input->post('post') == ''){$type="image";} else {$type="image-with-text";} 
     } 

     else {$pic = ""; $type = "text"; } 

      $result = $this->blog->addPost($_SESSION['user_id'], $type , $this->input->post('post'),$pic); 
     } 
$this->template->build('home_view',$this->data); 
} 

時上傳圖片超過3000的大向我顯示此消息

Array ([error] => 

The filetype you are attempting to upload is not allowed. 
) 

如何在我的視圖中讀取此錯誤?

============================================== ==

更新: -

錯誤messagelike這樣的: -

Array ([error] => 

The filetype you are attempting to upload is not allowed. 
) 
A PHP Error was encountered 

Severity: Notice 

Message: Array to string conversion 

Filename: mysql/mysql_driver.php 

Line Number: 552 
A PHP Error was encountered 

Severity: Warning 

Message: Cannot modify header information - headers already sent by (output started at E:\AppServ\www\cc\ccc\application\controllers\home.php:83) 

Filename: core/Common.php 

Line Number: 442 
A Database Error Occurred 

Error Number: 1054 

Unknown column 'Array' in 'field list' 

INSERT INTO `events` (`ev_user_id`, `ev_type`, `ev_text`, `ev_pic`, `ev_date`) VALUES (445, 'image', '', Array, '2013-10-03 23:51:47') 

Filename: E:\AppServ\www\cc\ccc\system\database\DB_driver.php 

Line Number: 330 

回答

0
$pic = $this->do_upload('inputUpProfile'); 
$this->data['upload_error'] = $pic['error']; 

然後在視圖:

echo $upload_error; 
+0

看到我的編輯帖子 – kamgfx

+0

您有3個錯誤,其中有2個錯誤在您的模型中,您沒有提供代碼。第一個錯誤告訴你到底什麼是錯誤的:文件的類型是不允許的。這是可以設置的配置。請閱讀用戶指南:http://ellislab.com/codeigniter/user-guide/ – stormdrain

8

,如果你有像

Array ([error] => 
    The filetype you are attempting to upload is not allowed. 
) 

錯誤的控制器,你可以像

if (!$this->upload->do_upload($field)) { 
    $error = array('error' => $this->upload->display_errors()); 
    $this->session->set_flashdata('error',$error['error']); 
    redirect('your_function_which_loads_the_view','refresh'); 
} 

,並在視圖頁面做類似

if($this->session->flashdata('error')){echo $this->session->flashdata('error');} 

請讓我知道,如果你面對任何問題。

+0

它對您有幫助嗎? – ABorty

+0

你好,先生,如果多個圖像正在升級並且一些非圖像類型文件也被添加到文件中,會發生什麼情況。 CI實際上給出錯誤,工作正常,但是在這個過程中一些文件正在升級。我應該怎麼做才能在CI中檢查所有文件? –