上载codeigniter时,将文件重复2 copise

时间:2019-07-07 00:54:02

标签: php codeigniter upload

在CodeIgniter中,当我将文件上传到特定文件夹时,它会上传文件的两个副本 到文件夹。我的意思是,它重复了文件,不知道为什么。 我该如何解决这个问题? 谢谢。

控制器:

 $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');
}

1 个答案:

答案 0 :(得分:1)

当然,由于您两次运行该功能,它将上传两个副本:

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

如果您想检查一次,请执行以下操作:

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