Php 我可以将图像的文件名保存在数据库中,但当我刷新屏幕时,它会消失-为什么?

Php 我可以将图像的文件名保存在数据库中,但当我刷新屏幕时,它会消失-为什么?,php,image,codeigniter,Php,Image,Codeigniter,我需要将图像保存到会话: 以下是我目前的代码: 型号: 控制器: 视图: " 宽度='300'高度='300'/> 我在想,我是否真的需要将图像作为链接保存到我的数据库中,而不是文件名?get profileimage函数旨在将图像扔回屏幕,使其保持在那里。再次感谢您的帮助。这一行是问题所在: $this->profileimages->putProfileImage($username, $img); 您正在保存的是图像,而不是路径。因此,正如您所说,您需要保存实际路径

我需要将图像保存到会话:

以下是我目前的代码:

型号:

控制器:

视图:


" 
宽度='300'高度='300'/>

我在想,我是否真的需要将图像作为链接保存到我的数据库中,而不是文件名?get profileimage函数旨在将图像扔回屏幕,使其保持在那里。再次感谢您的帮助。

这一行是问题所在:

$this->profileimages->putProfileImage($username, $img);
您正在保存的是
图像
,而不是路径。因此,正如您所说,您需要保存实际路径:

$img = '/web-project-jb/assets/puploads/'.$file_data['file_name'];
...etc
$this->profileimages->putProfileImage($username, $img);
希望这能帮助你解决你的问题

编辑

关于
会话
尝试执行以下操作:

$this->session->set_userdata($img); //note I've changed the name above as well.

查看codeigniter会话类以获取更多参考资料。

我该如何做?我回答“是”以确定答案是否对我有用:)我已经回顾了我收到的有用答案并对其进行了修改确定图像的url现在显示在数据库中-谢谢,但我认为问题在于我的getProfileImage函数打开。当我刷新页面时,图像仍然会从屏幕上消失。我是否应该将此会话->用户\u数据放入上载功能的其他部分?是吗?目前,只要我刷新,img仍然会消失
$this->profileimages->putProfileImage($username, $img);
$img = '/web-project-jb/assets/puploads/'.$file_data['file_name'];
...etc
$this->profileimages->putProfileImage($username, $img);
$this->session->set_userdata($img); //note I've changed the name above as well.