Changing name of the uploaded file in CodeIgniter (dots & underscores)

与世无争的帅哥 提交于 2019-12-10 13:16:48

问题


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

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

ADDED

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

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;
        }
    }

回答1:


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.



来源:https://stackoverflow.com/questions/5728059/changing-name-of-the-uploaded-file-in-codeigniter-dots-underscores

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!