Codeigniter Image重新登录后丢失但仍保存在数据库中

时间:2016-02-06 19:17:38

标签: php codeigniter

我在数据库中成功上传了一张用户照片和('/ uploads'文件夹)并且能够显示,但每次我退出时再次登录时图像/照片都会消失。

  

注销

<form  action="<?php echo $action;?>" method="POST" enctype="multipart/form-data"> 

// echo $action, refer to memberlogincontroller/editphoto

<a href="#"><img height="200px" width="200px"src="<?php echo base_url().'/uploads/'.$this->session->userdata('image'); ?>"> 

<input type="file" name="userfile" />
    <br /><br />

<input type="hidden" name="id" value="<?php echo $this->session->userdata('id'); ?>"/>
<input type="submit" name="submit" id="submit" class="btn btn-primary"  value="upload" />
</form>
  

控制器

<div class="description">
            <!--    <a href="#"><img height="200px" width="200px" src="<php echo base_url();?>uploads/no-avatar.jpg"></a>-->
                 <a href="#"><img height="200px" width="200px"src="<?php echo base_url().'/uploads/'.$this->session->userdata('image'); ?>"> 
                </div>
  

模型

{{1}}
  

上传图片视图

{{1}}
  

userprofile查看页面

{{1}}

1 个答案:

答案 0 :(得分:0)

$this->session->userdata('image')

尚未在$this->session->set_userdata($newdata);

中设置
foreach($query->result() as $rows)
    {
        //add all data to session
        $newdata = array(
                'id'            => $rows->id,
                'memberfname'   => $rows->memberfname,
                'memberlname'   => $rows->memberlname,
                'email'         => $rows->email,

                'logged_in'     => TRUE
           );
    }

$newdata中,您应该添加'image'