【问题标题】:file upload code igniter..not working文件上传代码点火器..不工作
【发布时间】:2013-01-24 01:12:04
【问题描述】:

这是在我的控制器中用于文件上传

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

我的代码有问题吗?上传失败。

【问题讨论】:

  • 定义not working。我们需要一些错误消息来处理。
  • do_upload() 中有什么内容?

标签: codeigniter upload


【解决方案1】:

在为上传类初始化和设置配置变量之前,不能简单地调用do_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'); //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.
}

您也可以参考 Codeigniter wiki

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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2011-09-07
    • 2015-07-09
    • 2012-03-05
    • 2015-07-05
    • 2018-05-19
    • 2011-08-11
    • 1970-01-01
    • 2013-09-26
    • 2013-12-05
    相关资源
    最近更新 更多