我想将图片上传到我的服务器,它工作正常,我已经加密了图片上的名称。
但现在我想更新数据库中的用户表,以便在用户的个人资料中显示图像。
我的问题是我无法找到如何将加密的图像名称插入名为“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/