• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug in File Upload Class?

#1
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 );
        }
    }
}
Reply

#2
(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.
Reply

#3
(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
Reply

#4
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
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.