我遇到了图片上传器的问题。我已经创建了图像上传器,它工作正常但我还需要编辑它们。 当我添加一个需要图像时,db列正确更新,但是如果不更改图像并保持原样,我会收到错误“列'图像'不能为空”
这是更新部分的代码:
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 :(得分: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']);
要
log_message('error',(string) $this->upload->display_errors());