在CodeIgniter中更改上传文件的名称(点和下划线) [英] Changing name of the uploaded file in CodeIgniter (dots & underscores)

查看:816
本文介绍了在CodeIgniter中更改上传文件的名称(点和下划线)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更改上传文件的名称时遇到了一些问题:

I got some problems with changing name of uploaded file:

$config = array(
        'allowed_types' => 'mp3',
        'file_name' => $fulltitle,       // Lets say we've entered 'a.s.d.f.mp3'
        'upload_path' => './music/'
    );
$this->load->library('upload', $config);        
$this->upload->do_upload(); 

但是,当我检查我的文件名时会显示我

But, when I check my filename it shows me


a.s_.d_.f_.mp3

a.s_.d_.f_.mp3

为什么CodeIgniter在每个点之前添加下划线之后第一个?如何禁用这个?
谢谢。

Why CodeIgniter add underscore before every dot after first one? How I can disable this? Thank you.

ADDED

system-> libraries-> Upload.php文件。

Well I found solution. system->libraries->Upload.php file.

994行,_prep_filename()函数。

Line 994, _prep_filename() function.

        $parts      = explode('.', $filename);
    $ext        = array_pop($parts);
    $filename   = array_shift($parts);

    foreach ($parts as $part)
    {
        if ( ! in_array(strtolower($part), $this->allowed_types) OR $this->mimes_types(strtolower($part)) === FALSE)
        {
            $filename .= '.'.$part.'_'; // Line 994
        }
        else
        {
            $filename .= '.'.$part;
        }
    }


推荐答案

添加'remove_spaces'=> FALSE 到你的配置数组,看看是否能解决这个问题。默认情况下,它设置为TRUE,但它只应该用下划线替换空格。它可能是与文件上传类的CI错误。

Try adding 'remove_spaces' => FALSE to your config array and see if that takes care of the problem. This is set to TRUE by default, but it should only be replacing spaces with underscores. It could be a CI bug with the file uploading class.

这篇关于在CodeIgniter中更改上传文件的名称(点和下划线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆