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

标签 codeigniter upload

这是在我的文件上传 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/

相关文章:

mysql - CodeIgniter 使用 n 个数组元素构建 LIKE 查询

php - 在 Javascript 中实现 PHP 常量的最佳方式

Codeigniter 在 helper 中获取 Controller 名称

php - 我应该如何处理Codeigniter应用程序中的错误

iphone - 如何处理使用 ios5 中的调度方法将记录上传到服务器

python - 通过 Flask/Python/Heroku 上传后在哪里可以找到文件?

php - 将 excel 导入多个表 - PHP 和 MYSQL (codeigniter)

c++ - 在 Mac 上通过 HTTP/HTTPS 和/或 FTP/FTPS 上传文件

android - 如何使用 Android koush/ion 动态形成请求

image - 如何在 webroot View 中显示图像