Igniter file upload code ... not working

This is in my controller for uploading files

$config['upload_path'] = './assets/images/b2b/banner-agent/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['file_name'] = "$banner2";
$this->load->library('upload', $config);
$this->upload->data();
$this->upload->do_upload();
$this->upload->initialize($config);

      

Are there any mistakes in my code? The download is not working.

+3


source to share


1 answer


You cannot just call the method do_upload

before initializing and setting the config variables for the load class.

You need to change your code like this:

$config['upload_path'] = './assets/images/b2b/banner-agent/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['file_name'] = $banner2;
$this->load->library('upload'); //initialize
$this->upload->initialize($config); //Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class
$this->upload->do_upload(); // do upload
if($this->upload->do_upload()){
    $this->upload->data(); //returns an array containing all of the data related to the file you uploaded.
}

      



You can refer to the Codeigniter wiki for this :

http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

Hope it helps.

+4


source







All Articles