删除Codeigniter中文件上传中的扩展名

时间:2013-11-21 14:20:16

标签: php codeigniter

我想使用CodeIgniter上传带有加密名称的文件。 但是,我尝试了两种可能性:

$config['file_name'] = md5($id);

或者:

$config['encrypt_name'] = TRUE;

两者都有效,但我的编目名称中有文件扩展名。上传文件时是否可以删除它? 当我看到上传系统库时,$ file-> ext在任何地方都使用..为什么要将文件扩展名放在加密名称中? 感谢。

2 个答案:

答案 0 :(得分:0)

实际上有一种更简单的方法:

if ($this->upload->do_upload())  // If file was uploaded
{           
    $data = $this->upload->data(); // Returns information about your uploaded file.
    $new_name=md5($id);
    $thumbnail = $new_name.$data['file_ext']; // Here it is
}

答案 1 :(得分:0)

打开system/libraries/Upload.php

do_upload功能

中删除或注释掉此代码
// If no extension was provided in the file_name config item, use the uploaded one
if (strpos($this->_file_name_override, '.') === FALSE)
{
  $this->file_name .= $this->file_ext;
}
else
{
  // An extension was provided, let's have it!
  $this->file_ext = $this->get_extension($this->_file_name_override);
}