在CodeIgniter中显示基于用户名文件名的图像


Display image based on username file name in CodeIgniter

我在一个网站上工作,其中在用户的个人资料,用户的照片将被显示。用户可以使用上传照片按钮上传他/她的照片,然后它将自动重命名为用户的用户名,并将被保存到名为'uploads'的根文件夹。

现在,我想在用户的个人资料页面上显示照片,但它不会显示。我认为这是因为我将文件名与文件扩展名或其他东西连接在一起的方式。

下面是目前为止的代码:

View.php
<img src="<?php echo base_url().'uploads/'.$userdata['usrname'];?>" width="200px" class="img-circle img-thumbnail" alt="avatar"><Br>

控制器

public function files(){
      $nga = $this->session->userdata('username');
      $data['usrname'] = $nga, ".JPG";
}
 <img src="<?php echo base_url().'uploads/'.$data['usrname'] = $this->session->userdata('username'). ".JPG";;?>" width="200px" class="img-circle img-thumbnail" alt="avatar"><Br>

This:

$data['usrname'] = $nga, ".JPG";

应该是这样的(用点代替逗号来连接):

$data['usrname'] = $nga . ".JPG";