douchun5976 2016-02-20 18:43
浏览 27
已采纳

如果用户没有照片codeigniter,则显示默认图像

In displaying my image getting it from the database is fine but I want to display the default image if no user hasn't uploaded a photo yet. I saved a no-avatar.jpg to my /uploads folder



Here is my display user image.

view

<img height="180px" width="180px"class="ppborder" src="<?php echo base_url().'/uploads/'.$this->session->userdata('image'); ?>"> 

upload

public function updatephoto($id)
    {
    if ((int)$id < 1)//$id is not an integer
    {
    redirect('Memberlogincontroller/member_view', 'refresh');
    }
    else{
    $this->load->helper(array('form','file','url'));
    $this->load->library('form_validation');
    $config_image = array(
        'upload_path'   => './uploads/',
        'allowed_types' => 'gif|jpg|png',
        'max_size'      => '1024',
        'overwrite'     => true

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

    if($this->form_validation->run()==false and empty($_FILES['userfile']['name'][0]))
        {
            $id = $this->session->userdata('id');
            $memberinfo = array(
                'error_image' => ''
            );
        $this->session->set_flashdata('flashError', 'Oops no photo selected', $memberinfo);         
        redirect('index.php/Memberlogincontroller/editphoto/'.$id, 'refresh');
        }       
    else
        {           
            $this->upload->do_upload();
             $data = array('upload_data' => $this->upload->data());
             $this->image_resize($data['upload_data']['full_path'], $data['upload_data']['file_name']);
             $id = $this->session->userdata('id');
             $this->db->where('id', $id);
             $query = $this->db->get('member'); 
            $data = array(
                'image' => $data['upload_data']['file_name']    
        );
        $this->db->update('member',$data,array('id'=>$id));          
        $this->session->set_userdata($data); 
        $this->session->set_flashdata('flashSuccess', 'Your photo has been updated.');
        redirect('index.php/Memberlogincontroller/getMember/'.$id, 'refresh');       
    }       
    }
    }

How to display my default image?

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 实值特征权重向量和特征选择,多分类
      • ¥15 INVEST年产水量模块结果出处理
      • ¥15 Neo4j 不显示关系
      • ¥15 这段代码有什么bug
      • ¥15 pip默认安装位置修改不成功
      • ¥15 C++ inline、staitc、const三合一谁能讲通透
      • ¥15 关于pyqt5中QThread的问题
      • ¥20 STM32基于HAL库使用串口发送16进制数组
      • ¥15 OpenCV报错 You can enable it via 'OPENCV_IO_ENABLE_OPENEXR'
      • ¥15 AT89C51的程序问题