Redov Kadour
Redov Kadour

Reputation: 29

Repeat the file to 2 copise while upload codeigniter

In CodeIgniter when I upload a file to a particular folder it uploads two copies of the file To folder. I mean, it repeats the file, I do not know why. How do I solve this problem? thank you.

Controller:

 $config['upload_path'] = './files/';
 $config['allowed_types'] = 'gif|jpg|png|jpeg|svg|rar|zip' ;
 $config['max_size'] = 220048;
 $config['encrypt_name'] = TRUE;

 $this->load->library('upload', $config, 'catalogupload3');
 // Create custom object for catalog upload
  $this->catalogupload3->initialize($config);
$this->catalogupload3->do_upload('userfile5');

if (!$this->catalogupload3->do_upload('userfile5')){

  $url_file = 'nofile' ;
  $file_name = 'false';
  $file_size = 'false';
}else {
  $this->catalogupload3->data();
  $url_file = $this->catalogupload3->data('file_name');
 $file_name = $_FILES['userfile5']['name'];
 $file_size = $_FILES['userfile5']['size'];
}

////

$config['upload_path'] = './files/32/';
 $config['allowed_types'] = 'gif|jpg|png|jpeg|svg|rar|zip' ;
 $config['max_size'] = 220048;
    $config['encrypt_name'] = TRUE;

 $this->load->library('upload', $config, 'catalogupload5');
 // Create custom object for catalog upload
  $this->catalogupload5->initialize($config);
$this->catalogupload5->do_upload('userfile7');

if (!$this->catalogupload5->do_upload('userfile7')){

  $url_file = 'nofile' ;
}else {
  $this->catalogupload5->data();
  $url_file_32 = $this->catalogupload5->data('file_name');
}

Upvotes: 0

Views: 57

Answers (1)

Sherif Salah
Sherif Salah

Reputation: 2153

Of course it will upload two copies because you ran the function twice:

// first run
$this->catalogupload3->do_upload('userfile5');
// second run
if (!$this->catalogupload3->do_upload('userfile5'))

If you wanna a check do it once:

// this is enough it will run it and return a bool
if (!$this->catalogupload3->do_upload('userfile5'))

Upvotes: 1

Related Questions