CodeIgniter Forums
Bug in File Upload Class? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Bug in File Upload Class? (/showthread.php?tid=482)



Bug in File Upload Class? - Stefan57 - 12-09-2014

I'm trying to upload a file and overwrite if exists on server but I always get error msg like:
"File exists, overwrite is FALSE, could not save over file ./uploads/avatars/1.jpg"

Here is my code where 'overwrite' is TRUE... Any idea how to solve this?

Code:
if( isset($_FILES['userfile']['name']) ) {
    if( $_FILES['userfile']['name'] != "") {
        $config['upload_path'] = 'uploads/avatars/temp/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['remove_spaces'] = true;
        $config['overwrite'] = true;
        $config['encrypt_name'] = true;
        $config['max_size'] = '3000';
        $config['max_width']  = '3000';
        $config['max_height']  = '3000';
        $this->load->library('upload', $config);

        if (!$this->upload->do_upload('userfile')) {
            // Failed
            $error = array('error' => $this->upload->display_errors());
            print_r($error);
            exit();
        } else {
            // Success
            $image = $this->upload->data();
            var_dump( $image );
        }
    }
}



RE: Bug in File Upload Class? - Avenirer - 12-09-2014

(12-09-2014, 06:33 AM)Stefan57 Wrote: I'm trying to upload a file and overwrite if exists on server but I always get error msg like:
"File exists, overwrite is FALSE, could not save over file ./uploads/avatars/1.jpg"

Here is my code where 'overwrite' is TRUE... Any idea how to solve this?


Code:
if( isset($_FILES['userfile']['name']) ) {
    if( $_FILES['userfile']['name'] != "") {
        $config['upload_path'] = 'uploads/avatars/temp/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['remove_spaces'] = true;
        $config['overwrite'] = true;
        $config['encrypt_name'] = true;
        $config['max_size'] = '3000';
        $config['max_width']  = '3000';
        $config['max_height']  = '3000';
        $this->load->library('upload', $config);

        if (!$this->upload->do_upload('userfile')) {
            // Failed
            $error = array('error' => $this->upload->display_errors());
            print_r($error);
            exit();
        } else {
            // Success
            $image = $this->upload->data();
            var_dump( $image );
        }
    }
}

Make sure the folder and files are writable.


RE: Bug in File Upload Class? - Stefan57 - 12-09-2014

(12-09-2014, 07:42 AM)Avenirer Wrote: Make sure the folder and files are writable.

Folders/Files are writeable and upload works fine first time, but if I re-upload and need to write over previous file, I get this error:

"File exists, overwrite is FALSE, could not save over file ./uploads/avatars/temp/1.png"

Even I have this set in config:
$config['overwrite'] = true;

If it matter I run this under WAMP in my Win7 computer ... have not tried on real server yet ...

Any ideas how to make upload / overwrite work ????

/Stefan


RE: Bug in File Upload Class? - Stefan57 - 12-09-2014

I found the problem so you can ignore this thread!

The problem was NOT with codeigniters File Upload Class Angel
It was in the Image_moo class, where I also had to set overwrite to TRUE Big Grin

/Stefan57