文件上传代码点火器..不起作用 [英] file upload code igniter..not working

查看:72
本文介绍了文件上传代码点火器..不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

您不能简单地调用 do_upload 方法在初始化和设置上载类的配置变量之前。

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.
}

您也可以参考 Codeigniter Wiki

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

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

希望这会有所帮助。

这篇关于文件上传代码点火器..不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆