3

This is in my controller for file upload

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

is there any wrong with my code? The upload not working.

2
  • define not working. We need some error message to work on. Commented Feb 8, 2013 at 9:48
  • Whats in do_upload()? Commented Feb 8, 2013 at 9:56

1 Answer 1

4

You can not simply call do_upload method before initializing and setting config variables for the upload class.

You need to modify 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 consult Codeigniter wiki for that too:

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

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.