file upload code igniter..not working

烈酒焚心 提交于 2019-12-12 15:24:31

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14769709/file-upload-code-igniter-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!