【问题标题】:codeigniter image upload (get the crypted name)codeigniter 图片上传(获取加密名称)
【发布时间】:2011-01-14 18:11:01
【问题描述】:

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

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

我的问题是我不知道如何在名为“users”的数据库表中插入加密的图像名称,而用户表中的毡字段是“profile_picture”。

我试过了

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

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

【问题讨论】:

标签: database codeigniter submit


【解决方案1】:

您必须向我们展示一些代码,但无论如何您需要在上传文件时设置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() 将返回一个 array 保存上传文件的信息,refer
所以你需要做的是:

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

然后使用:

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

现在注意文档:

file_name 文件名 已上传,包括文件 扩展名。
orig_name 原文 文件名。这仅在您使用时才有用 使用加密名称选项。

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

【讨论】:

  • 我已经更新了我的任务并且我已经对其进行了加密,我只想将我数据库中的用户表更新为加密名称
  • 在尝试您的示例后出现此错误“字段列表”中的未知列“数组”更新users SET profile_picture = 数组在哪里username = 'simonj'
  • @simon:当然不行!抱歉正在查看“加密文件”位,但没有注意到您正在添加整个数组。 :-)
【解决方案2】:

请参阅此处以获得更好的清晰度

http://codeigniter.com/user_guide/libraries/file_uploading.html

假设您将上传数据保存在一个名为 upload_data 的数组中。

加载数据库类

$this->load->database();

然后在模型或控制器中..

插入表中名为 cryptedname 的字段

$cryptedname = $upload_data['file_name']; $this->db->set('cryptedname', $cryptedname);

插入到名为image的表中

$this->db->insert('image');

【讨论】:

  • 好吧,我还是做不到:我有这个 $profilBilledNavn = $this->upload->data('file_name'); $this->db->where('username', $this->input->post('username')); $this->db->update('users', $profilBilledNavn);
  • @simon:嗯?!!你可以编辑你的问题并添加你的代码..并实际解释你在做什么或试图做什么!
猜你喜欢
  • 2012-09-02
  • 2015-10-22
  • 1970-01-01
  • 2013-02-10
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
相关资源
最近更新 更多