Welcome Guest, Not a member yet? Register   Sign In
Upload Class Problem - two files are copied to my folder?
#1

[eluser]tinawina[/eluser]
I am using the file upload class. When I set $config['overwrite'] = FALSE so that a number is appended to the end of a filename if the same filename already exists in my folder, two files are uploaded -- eg., filename.pdf and filename1.pdf.

If I set the variable to TRUE, just one instance of the file occurs. I thought I was calling $this->upload->do_upload() twice which would explain this, but I'm not. Here's my code and here's the code in the Upload class that handles overwriting. Any ideas? Thanks for your help!

My code -
Code:
function uploadFile()
    {    

        $config['upload_path']        = '/path/to/my/uploads/folder';
        $config['allowed_types']    = 'pdf|xls|odt|doc|rtf|gif|jpeg|jpg|png|tif|tiff|csv|txt';
        $config['max_size']            = '1000';
        $config['max_width']        = '1024';
        $config['max_height']        = '768';
        $config['overwrite']        = FALSE;
        $config['remove_spaces']    = TRUE;

        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        
        $this->upload->do_upload();

        if ( !$this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());

            $display = '';
            foreach ($error AS $problem)
            {
                $display .= '<p>' . $problem . '</p>';
            }
            $this->view->set('errors', $display);
            $this->view->load('templates/maintain_listings');
        }    
        else
        {
            // DONE;
        }
    }

Upload Class method (lines 221-231)

Code:
$this->orig_name = $this->file_name;

        if ($this->overwrite == FALSE)
        {
            $this->file_name = $this->set_filename($this->upload_path, $this->file_name);
            
            if ($this->file_name === FALSE)
            {
                return FALSE;
            }
        }
#2

[eluser]Pascal Kriete[/eluser]
You are calling the do_upload function twice:
Code:
$this->upload->do_upload();

if ( !$this->upload->do_upload())

Get rid of the first one and it should work.
#3

[eluser]tinawina[/eluser]
Yeah! THANK YOU!




Theme © iAndrew 2016 - Forum software by © MyBB