我被困在圖像上傳的問題。我創建的圖片上傳器工作正常,但我也需要編輯它們。 當我添加一個需要圖像的數據庫列正確更新,但我如果不改變形象,離開它,因爲它是,我得到一個錯誤「列‘形象’不能爲空」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;
}
你在'回聲得到var_dump($ this-> input-> post('current_image'))'? – GBD
@GBD如果我在if($ this-> input-> post('image')){}中使用它,我從db獲得值,但是如果我在其他{}中使用它,我不會得到enything –
你能在其他部分回顯「你好」?看到它執行或沒有圖像文件時 – GBD