CodeIgniter Forums
[SOLVED] Upload bug or something else? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Upload bug or something else? (/showthread.php?tid=16651)



[SOLVED] Upload bug or something else? - El Forum - 03-12-2009

[eluser]Armchair Samurai[/eluser]
I'm having an odd issue with the upload library - it's adding extra underscores to the filename if it has more than one dot. For example, if I upload a file called foo.bar.jpg, the filename will be rewritten as foo.bar_.jpg. This occurs both on my local as well as live servers. Has anyone else encountered this and has a solution?

Just in case I'm missing something totally obvious, here's the code to upload files:
Code:
function upload()
{
    $this->load->library('upload', array(
        'upload_path' => $this->dir,
        'allowed_types' => 'jpg|gif|png|txt|pdf'
    ));
    $this->lang->load('upload_file');
    
    if ( ! $this->upload->do_upload('upload'))
    {
        show_error($this->upload->display_errors('<p>', '</p>'));
        exit;
    }
    else
    {
        $data = $this->upload->data();
        
        set_flash(sprintf($this->lang->line('upload_complete'), $data['file_name']));
        redirect($this->l10n->code().'admin/files/index', 'Location');
    }
}



[SOLVED] Upload bug or something else? - El Forum - 03-12-2009

[eluser]TheFuzzy0ne[/eluser]
That will only happen then there's a whitespace in the filename. By default, whitespaces are replaced with underscores.

Also, did you know you can load the language helper and then just use:
Code:
lang('lang_key');

# as opposed to:

$this->lang->line('lang_key');



[SOLVED] Upload bug or something else? - El Forum - 03-12-2009

[eluser]Armchair Samurai[/eluser]
Thanks for the reply, but there is no whitespace in the file names - that would have been a little too obvious.

I took a look at the source code for the Upload library and found the culprit -_prep_filename() - and fixed it.

Also - I'm aware of the Language helper, but I prefer to use libraries in controllers and helpers in views in general - it's just a personal coding preference.