Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter:更新图像和显示_Codeigniter - Fatal编程技术网

Codeigniter:更新图像和显示

Codeigniter:更新图像和显示,codeigniter,Codeigniter,我在更新图像时遇到了一个问题。我已经创建了图像上传,工作良好,但我也希望它被更新。当我添加需要的图像时,它会正确更新,但如果我不想更改图像并保持原样,则无法检索我的当前图像。请帮帮我 控制器 public function insert() { $data['s_em']=$this->input->post('s_em'); $data['s_na']=$this->input->post('s_na'); $conf

我在更新图像时遇到了一个问题。我已经创建了图像上传,工作良好,但我也希望它被更新。当我添加需要的图像时,它会正确更新,但如果我不想更改图像并保持原样,则无法检索我的当前图像。请帮帮我

控制器

public function insert()
        {
       $data['s_em']=$this->input->post('s_em');
       $data['s_na']=$this->input->post('s_na');
    $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt';
             $this->load->library('upload', $config);
                                  if ( ! $this->upload->do_upload('file'))
                                      {
                              $error = array('error' => $this->upload->display_errors());

                                      }

                             else
                                 {

                        $data['file']=$this->upload->data('file_name');


                 } 

              $this->Students_m->db_ins($data);


         $this->load->view('admin/newstudents');


     }

    public function edit($id)
     {
        $dt['da']=$this->Students_m->db_edit($id)->row_array();
        $this->load->view('admin/st_edt',$dt);
      }   

public function update()
{
    $id=$this->input->post("id");

    $s_em=$this->input->post("s_em");
    $s_na=$this->input->post("s_na");

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] =     'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt';
    $this->load->library('upload', $config);
    if ( ! $this->upload->do_upload('file'))
    {
        $error = array('error' => $this->upload-   >display_errors());
    }
    else
    {
        $upload_data=$this->upload->data();
        $image_name=$upload_data['file_name'];
    }

$data=array('s_em'=>$s_em,'s_na'=>$s_na,'file'=>$image_name);
$this->Students_m->db_update($data,$id);
}

redirect("admin/students");
}
型号

 public function db_ins($data)
     {
    $query=$this->db->insert('student',$data);
    return $query;   
    }
public function db_edit($id)
{
    return $this->db->get_where('student', array('id'=>$id));
}
public function db_update($data,$id)
{
    $this->db->where('id', $id);       
    $this->db->update('student', $data);
}
看法


个人资料
“height=“205”width=“205”>
图片:*
电邮地址:*

上载同名图像时请务必小心。该图像已成功上载,但您无法看到前端的更改是否具有相同的URL和名称,这是因为您的浏览器缓存了以前的图像

确保首先在服务器上成功更新映像

    public function update()
    {
        $id=$this->input->post("id");

        $s_em=$this->input->post("s_em");
        $s_na=$this->input->post("s_na");


 if($_FILES[file]['name']!="")
            {
    $config['upload_path'] = './uploads/';
        $config['allowed_types'] =     'gif|jpg|png|jpeg|jpe|pdf|doc|docx|rtf|text|txt';
        $this->load->library('upload', $config);
        if ( ! $this->upload->do_upload('file'))
        {
            $error = array('error' => $this->upload-   >display_errors());
        }
        else
        {
            $upload_data=$this->upload->data();
            $image_name=$upload_data['file_name'];
        }
    }
    else{
                $image_name=$this->input->post('old');
            }
$data=array('s_em'=>$s_em,'s_na'=>$s_na,'file'=>$image_name);
$this->Students_m->db_update($data,$id);
}
在视图文件中添加以下内容

<input type="hidden"  id="old"  name="old"  value="<?php echo $da['file']   ?>">

能否添加查看页面**是**@vimal sy您正在将文件移动到文件夹中..对..我没有获得上载代码..我添加了上载代码。请检查。。
<input type="hidden"  id="old"  name="old"  value="<?php echo $da['file']   ?>">