PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 28, 2022

[FIXED] Repeat the file to 2 copise while upload codeigniter

 January 28, 2022     codeigniter, php, upload     No comments   

Issue

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

Solution

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'))


Answered By - Sherif Salah
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing