gpt4 book ai didi

codeigniter - 文件上传代码点火器..不工作

转载 作者:行者123 更新时间:2023-12-04 03:00:37 24 4
gpt4 key购买 nike

这是在我的文件上传 Controller 中

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

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

最佳答案

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

希望这对您有所帮助。

关于codeigniter - 文件上传代码点火器..不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14769709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com