我正在尝试更新我的信息:在localhost中它不是错误变量:img,但是当我将它上传到服务器时,它是错误的,例如遇到了PHP错误:
严重性:通知消息:未定义变量:img文件名:controllers / pages.php行号:79 ....
function update_ads($id)
{
if($this->input->post('update_ads'))
{
$this->db->select('img');
$this->db->where('id',$id);
$query = $this->db->get('tblp_label_slides',$id);
foreach($query->result() as $row)
{
$img = $row->img;
$image = $this->session->set_userdata('img', $img);
}
if($img!='')
{
$config['upload_path'] ='./images/ads';
$config['allowed_types'] ='jpg|jpeg|gif|png';
$config['max_size'] = 1024*8;
$config['encrypt_name'] = true;
$this->upload->initialize($config);
$this->load->library('upload', $config);
if(!$this->upload->do_upload('imgfile'))
{
$edit['update'] = $this->mod_write->up_adv($this->session->userdata('img'), $id);
$this->session->set_flashdata(array('success_update' => 12));
redirect('pages/ads_right');
}
else
{
$img_content = $this->upload->data('imgfile');
$edit['update'] = $this->mod_write->up_adv($img_content['file_name'], $id);
unlink("./images/ads/".$img);
$this->session->set_flashdata(array('success_update' => 12));
redirect('pages/ads_right');
}
}
else
{
$config['upload_path'] = './images/ads';
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['max_size'] = 1024*8;
$config['encrypt_name'] = true;
$this->upload->initialize($config);
$this->load->library('upload', $config);
if(! $this->upload->do_upload('imgfile'))
{
$edit['update'] = $this->mod_write->up_adv('', $id);
$this->session->set_flashdata(array('success_update' => 12));
redirect('pages/ads_right');
}
else
{
$img_content = $this->upload->data('imgfile');
$edit['update'] = $this->mod_write->up_adv($img_content['file_name'], $id);
unlink("./images/ads/".$img);
$this->session->set_flashdata(array('success_update' => 12));
redirect('pages/ads_right');
}
}
}
}
我的模特
function up_adv($img_content)
{
$id = $this->uri->segment(3);
$data = array(
'dates'=>date('Y-m-d H:i:s'),
'url'=>replace_tag($this->input->post('url')),
'title'=>replace_tag($this->input->post('title')),
'img'=>$img_content,
'type'=>$this->input->post('type')
);
$this->db->where('id',pde($id))
->update('tblp_label_slides',$data);
}
答案 0 :(得分:0)
我可能错了,但我认为问题是如何验证$img
。
更改if ($img != '')
至if (isset($img) && trim($img) !== '')
如果未声明$img
,如果您的查询未返回任何行,则会停止发生错误。
希望这有帮助!