Php CodeIgniter不';加载上载库
我在加载CodeIgniter库时遇到问题 我已经用CODEGITENER建立了三(3)个网站,所以我认为自己熟悉这个框架。 问题只在于上传库。我尝试了多种功能,但仍然不起作用 我甚至试过用它 在谷歌我找不到任何答案,有人知道它可能是什么吗Php CodeIgniter不';加载上载库,php,codeigniter,codeigniter-form-helper,Php,Codeigniter,Codeigniter Form Helper,我在加载CodeIgniter库时遇到问题 我已经用CODEGITENER建立了三(3)个网站,所以我认为自己熟悉这个框架。 问题只在于上传库。我尝试了多种功能,但仍然不起作用 我甚至试过用它 在谷歌我找不到任何答案,有人知道它可能是什么吗 class Admin extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->library('se
class Admin extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->library('session');
$this->load->library('v');
$this->load->model('admin_model');
}
public function upload_a_thing($set = null){
$this->load->helper(array('form', 'url'));
if(!$set){
$this->load->view('admin/upload_a_thing');
}else{
$this->load->library('Upload');
if (!$this->upload->do_upload('userfile')){
echo $this->upload->display_errors();
} else {
$file = $this->upload->data();
// $product = $this->admin_model->get_products($id);
$newFilePath = $config['upload_path'].'try.jpg';
$file['file_name'] = str_replace(" ","_",$file['file_name']);
rename($config['upload_path'].$file['file_name'], $newFilePath);
}
}
}
编码点火器错误
PHP错误
为斯帕里编辑
如果您的表单如下所示:
<input type="file" class="input" name="logo" />
do_upload('logo');
<input type="file" class="input" name="userfile" />
do_upload();
如果是这样的话:
<input type="file" class="input" name="logo" />
do_upload('logo');
<input type="file" class="input" name="userfile" />
do_upload();
做这样的事
if (!$this->upload->do_upload('userfile')){
echo $this->upload->display_errors();
}
你的代码
$this->load->library('Upload');
,upload
应为小写,并且很可能是库未加载的原因
此外,如果缺少
$config
数组,则说明您没有遵循文档中的示例代码:
$config['upload_path'] = './uploads/'; // <- preferences
$this->load->library('upload', $config); // <- load library and set configuration
$config['upload_path']='。/uploads/';//加载->库('upload',$config);//加载->库(“上载”);//初始化($config);//这是我的输入,你能分享整个类吗?将它改为整个函数、构造函数和类名检查上次编辑时,它还不起作用,实际上我从我做的另一个网站复制了这段代码,在那里它起作用了。@EyalAvitan,不知道还能告诉你什么。除了你发布的代码被破坏之外,这个库为我工作。您确定已正确设置上载文件夹的权限吗?您是否仍然收到与以前相同的错误消息?我想我找到了一个提示,我尝试加载另一个库(我创建的库),但我遇到了相同的问题,然后我使用了get_instance函数(只是为了检查),它正常工作。现在,我在一个控制器,所以我真的不需要使用这个任何机会,它可以帮助我们得到它发生的原因(我真的不想在我的网站上使用get_实例&我不想让这个错误保持打开状态。)谢谢你的帮助help@EyalAvitan,不知道你是怎么弄坏的,也不知道你现在问我什么。。。听起来和我们开始时完全不同。
// 'upload' library is "auto-loaded" // <- load library
$config['upload_path'] = './uploads/'; // <- preferences
$this->upload->initialize($config); // <- set configuration