database - codeigniter 图片上传(获取加密名称)

标签 database codeigniter submit

我想将图片上传到我的服务器,它工作正常,我已经加密了图片上的名称。

但现在我想更新数据库中的用户表,以便在用户的个人资料中显示图像。

我的问题是我无法找到如何将加密的图像名称插入名为“users”的数据库表中,而用户表中的 felt 字段是“profile_picture”。

我试过了

$profilBilledNavn = $this->upload->data('file_name');
$this->db->where('username', $this->input->post('username'));
$this->db->update('users', $profilBilledNavn); 

但它不起作用。我做错了什么?

最佳答案

您必须向我们展示一些代码,但无论如何您需要在上传文件时设置encrypt_name:

$config['encrypt_name'] = TRUE;

编辑:
根据您的更新,您的代码应为:

$profilBilledNavn['profile_picture'] = $this->upload->data('file_name');
$this->db->where('username', $this->input->post('username'));
$this->db->update('users', $profilBilledNavn);

编辑 2:
请注意,$this->upload->data() 将返回一个包含上传文件信息的数组refer .
所以你需要做的是:

$file_array = $this->upload->data('file_name');

然后使用:

$profilBilledNavn['profile_picture'] = $file_array['file_name'];

现在注意文档:

file_name The name of the file that was uploaded including the file extension.
orig_name The original file name. This is only useful if you use the encrypted name option.

因此,由于您正在使用 encrypt_name,因此您应该使用第一个选项 (file_name) 来更新您的数据库。

关于database - codeigniter 图片上传(获取加密名称),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4694396/

相关文章:

php - 根据用户 session 关联 Mysql 表

php - 从数据库中获取喜欢的帖子的 ID

php - google map 多标记工具提示仅显示在 firefox 中的第一个标记上

php - php 表单提交按钮不起作用

php - 如何实现动态数据库列?

数据库架构推荐

php - 在 CodeIgniter 的每个页面上创建数据库生成的菜单?

php - Codeigniter - Ajax Post 不工作

jquery - 为什么 Jquery commit() 失败并出现错误?

javascript - 提交后水印出现在 Canvas 上