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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.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
Php 更新codeigniter上的图像_Php_Codeigniter_Updates_Crud - Fatal编程技术网

Php 更新codeigniter上的图像

Php 更新codeigniter上的图像,php,codeigniter,updates,crud,Php,Codeigniter,Updates,Crud,我被困在从codeigniter生成更新图像的过程中,我想在更新图像时替换图像,但代码不起作用。 这是我的密码: 这是控制器: 这是一款 public函数updatefoto($userId){ 如果($this->input->post('submit')){ $config['upload_path']=”/uploads/images/”; $config['allowed_types']='gif | jpg | png | jpeg'; $config['max_size']='200

我被困在从codeigniter生成更新图像的过程中,我想在更新图像时替换图像,但代码不起作用。 这是我的密码:

这是控制器:

这是一款

public函数updatefoto($userId){
如果($this->input->post('submit')){
$config['upload_path']=”/uploads/images/”;
$config['allowed_types']='gif | jpg | png | jpeg';
$config['max_size']='2000';
$config['max_width']='2000';
$config['max_height']='2000';
$config['file_name']='gambar-'.trim(str_replace(“,”,date('dmYHis'));
$this->load->library('upload',$config);
如果(!$this->upload->do_upload(“gambar”)){
$error=array('error'=>this->upload->display_errors('','');
$this->load->view('view\u ubah\u data-profile',$error);
}否则{
$nama=$this->upload->data('file_name');
$this->db->where('id',$userId);
$this->db->update('foto',array('nama_foto'=>$nama));
重定向(“查看数据配置文件”,“刷新”);
}
}
}
最后一个是视图


上载/图像/“cclass=“img缩略图”alt=“avatar”>
上传一张不同的照片。。。
上传
谢谢,谢谢你的帮助:)

我是这样做的

编辑-类构造

class Team extends CI_Controller {
 function __construct()
 {
    parent::__construct();
    $this->load->library('form_validation');
    $this->load->helper(array('form', 'url'));
    $this->load->model('team_model');
 }


 public function do_upload()
 {
    $config['upload_path']          = './uploads/';
    $config['allowed_types']        = 'gif|jpg|png';
    $config['max_size']             = 100;
    $config['max_width']            = 1024;
    $config['max_height']           = 768;

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

    if ( ! $this->upload->do_upload('userfile1'))
    {
        $data['errors'] = array('error' => $this->upload->display_errors());
        $data['client_Id']=$this->team_model->getUserId($email);
        $data['pic']=$this->team_model->getImage($data['client_Id']['id']);
        // Here I load my Views
    }
    else
    {
        $upload_data = $this->upload->data(); 
        $file_name=$upload_data['file_name'];
        $email=$this->session->userdata['email'];
        $data['client_Id']=$this->team_model->getUserId($email);
        $data['pic']=$this->team_model->getImage($data['client_Id']['id']);
        // If there is no image insert one other wise update
        if($data['pic']['image']!=''){
            $this->team_model->updateEmployeeImage($data['pic']['id'],$file_name);
            $data['success']='Congratulations! Image Updated Successfully';
        }else{
            $this->team_model->InsertEmployeeImage($data['client_Id']['id'],$file_name);
            $data = array('upload_data' => $this->upload->data());
            $data['success']='Congratulations! Image Uploaded Successfully';
        }
        $file_name=$upload_data['file_name'];
        $email=$this->session->userdata['email'];
        $data['client_Id']=$this->team_model->getUserId($email);
        $data['pic']=$this->team_model->getImage($data['client_Id']['id']);

        // Here I load my Views
    }
 }
}
编辑-模型功能

public function InsertEmployeeImage($id,$image){
    $Image=array(
        'id'                    => '',
        'team_id'             => $id,
        'image'                 => $image
    );
    $this->db->insert('teams_image',$Image);
    return ;
}

public function updateEmployeeImage($id,$img){
     $this->deleteOldImage($id);
     $pic=array(
        'image'      =>  $img
    );
    $this->db->WHERE('id',$id)->update('teams_image',$pic);
}

更新不在模型中的控制器中的图像请遵循@MalikMudassar我想更新图像不插入/上载图像/无论更新还是插入新图像,都将使用相同的方法。要更新图像,请显示最后一个图像,保留id,如果需要,请通过类似于控件的按钮删除该图像。或者使用相同的代码上载另一个图像,但在e model函数,您可以在数据库中保存图像名称,只需将其替换为旧文件,然后取消旧文件的链接即可将其从服务器中删除,此函数位于my中controller@Firm模型函数应该用来和数据库交互,向数据库发送数据,从数据库获取数据。我们在控制器中做的其他事情。如果你们能看到我是calling team_model函数用于不同的事情,比如从他的电子邮件中获取客户端详细信息等。在IF语句中,您可以看到我正在调用team_model函数updateEmployeeImage()和InsertEmployeeImage()这两个功能都在我的模型中。所以我使用模型,但不是用于上传图像,而是用于将数据存储到数据库并将其返回。这是您的代码,照片中的id是电子邮件吗?我可以看看您的团队模型吗?
          <div class="col-md-4 col-sm-6 col-xs-12">
        <form action="users/updatefoto" method="post" id="updateUserImage">
          <div class="text-center">

            <img src="<?php echo base_url();?>uploads/images/<?php echo $userData['nama_foto']  ?>" cclass="img-thumbnail" alt="avatar">
            <h6>Upload a different photo...</h6>
            <input type="file" class="text-center center-block well well-sm" name="gambar" id="files" accept="image/*" required>
            <button type="submit" value="Upload" name="submit" class="btn btn-primary">
            <i class="fa fa-upload" aria-hidden="true"></i>upload
          </button>
          </div>
        </form>
      </div>
class Team extends CI_Controller {
 function __construct()
 {
    parent::__construct();
    $this->load->library('form_validation');
    $this->load->helper(array('form', 'url'));
    $this->load->model('team_model');
 }


 public function do_upload()
 {
    $config['upload_path']          = './uploads/';
    $config['allowed_types']        = 'gif|jpg|png';
    $config['max_size']             = 100;
    $config['max_width']            = 1024;
    $config['max_height']           = 768;

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

    if ( ! $this->upload->do_upload('userfile1'))
    {
        $data['errors'] = array('error' => $this->upload->display_errors());
        $data['client_Id']=$this->team_model->getUserId($email);
        $data['pic']=$this->team_model->getImage($data['client_Id']['id']);
        // Here I load my Views
    }
    else
    {
        $upload_data = $this->upload->data(); 
        $file_name=$upload_data['file_name'];
        $email=$this->session->userdata['email'];
        $data['client_Id']=$this->team_model->getUserId($email);
        $data['pic']=$this->team_model->getImage($data['client_Id']['id']);
        // If there is no image insert one other wise update
        if($data['pic']['image']!=''){
            $this->team_model->updateEmployeeImage($data['pic']['id'],$file_name);
            $data['success']='Congratulations! Image Updated Successfully';
        }else{
            $this->team_model->InsertEmployeeImage($data['client_Id']['id'],$file_name);
            $data = array('upload_data' => $this->upload->data());
            $data['success']='Congratulations! Image Uploaded Successfully';
        }
        $file_name=$upload_data['file_name'];
        $email=$this->session->userdata['email'];
        $data['client_Id']=$this->team_model->getUserId($email);
        $data['pic']=$this->team_model->getImage($data['client_Id']['id']);

        // Here I load my Views
    }
 }
}
public function InsertEmployeeImage($id,$image){
    $Image=array(
        'id'                    => '',
        'team_id'             => $id,
        'image'                 => $image
    );
    $this->db->insert('teams_image',$Image);
    return ;
}

public function updateEmployeeImage($id,$img){
     $this->deleteOldImage($id);
     $pic=array(
        'image'      =>  $img
    );
    $this->db->WHERE('id',$id)->update('teams_image',$pic);
}