2012-11-04 71 views
2

我被困在圖像上傳的問題。我創建的圖片上傳器工作正常,但我也需要編輯它們。 當我添加一個需要圖像的數據庫列正確更新,但我如果不改變形象,離開它,因爲它是,我得到一個錯誤「列‘形象’不能爲空」codeigniter圖像更新

這是對於更新部分代碼:

else if ($type == 'update') 
{ 

    if($this->input->post('image')) { 
     $fdata = $this->savenew(); 
     $data['image'] = $fdata['upload_data']['file_name']; 

    } else { 
     $data['image'] = $this->input->post('current_image'); 


    } 

    $return = $this->add_radio_model->update($id, $data); 
} 

很抱歉,如果我不是很明確

編輯:

 private function savenew(){     

    $config['upload_path'] = './assets/'; //Make SURE that you chmod this directory to 777! 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = '0'; // 0 = no limit on file size (this also depends on your PHP configuration) 
    $config['remove_spaces']=TRUE; //Remove spaces from the file name 

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

    if (! $this->upload->do_upload('image')) 
    { 
      $data['error']= array('error' => $this->upload->display_errors()); 
      log_message('error',$data['error']); 
      } 
      else 
       { 
       $data = array('upload_data' => $this->upload->data()); 

       } 
     return $data; 
    } 
+0

你在'回聲得到var_dump($ this-> input-> post('current_image'))'? – GBD

+0

@GBD如果我在if($ this-> input-> post('image')){}中使用它,我從db獲得值,但是如果我在其他{}中使用它,我不會得到enything –

+0

你能在其他部分回顯「你好」?看到它執行或沒有圖像文件時 – GBD

回答

1

由於根據我們的意見線程,在這裏你需要改變你的代碼

else if ($type == 'update') 
{ 
    if($this->input->post('image')) { 
     $fdata = $this->savenew(); 
     // first always set current image 
     $data['image'] = $this->input->post('current_image'); 
     // second check if new image added if yes, then update otherwise keep original image as it is 
     if(isset($fdata['upload_data'])){ 
      $data['image'] = $fdata['upload_data']['file_name']; 
     } 
    } 
    $return = $this->add_radio_model->update($id, $data); 
} 

對於第二個問題:A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: libraries/Log.php Line Number: 99

變化:

$data['error']= array('error' => $this->upload->display_errors()); 
log_message('error',$data['error']); 

TO

log_message('error',(string) $this->upload->display_errors()); 
+0

同樣的php通知,當我不插入任何圖像。 '遇到了PHP錯誤 嚴重性:注意 消息:數組字符串轉換 文件名:庫/ Log.php 行號:99' –

+0

代碼的偉大工程,但唯一的問題是,PHP通知 –

+0

我想這個問題是在Log.php中的Log.php – GBD