【问题标题】:Fatal error: Call to undefined method CI_Upload致命错误:调用未定义的方法 CI_Upload
【发布时间】:2015-01-28 20:53:16
【问题描述】:

我已经在其他地方使用 codeigniter 上传类,上传 pdf 文件没有问题。现在,我正在尝试实现一个基本的图像上传器。这是我的控制器的代码:

class Upload_image extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->model('queries_model');
        $this->load->helper(array('form', 'url'));
        $this->load->library(array('form_validation', 'session', 'common'));
    }

    function index()
    {
        if ($this->session->userdata('logged_in'))
        {
            $id            = $this->input->get('id');
            $is_image      = $this->input->get('is_image');
            $data['title'] = ucfirst('Subir imagen');
            $pck_info      = $this->queries_model->get_excursion_by_id($id, 1);

            $this->load->view('admin/common/header', $data);
            $this->load->view('admin/upload_image', array('error' => ' ', 'pck_name' => $pck_info[0]->title, 'is_image' => $is_image));
            $this->load->view('admin/common/footer');
        }
        else
        {
            redirect('admin/login', 'refresh');
        }
    }

    function do_image_upload()
    {
        $config['upload_path']   = './assets/img/most-popular';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']      = '100';
        $config['max_width']     = '1024';
        $config['max_height']    = '768';
        $config['overwrite']     = true;

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_image_upload())
        {
            $error         = array('error' => $this->upload->display_errors('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>', '</div>'));
            $data['title'] = ucfirst('Subir información');

            $this->load->view('admin/common/header', $data);
            $this->load->view('admin/upload_image', $error);
            $this->load->view('admin/common/footer');
        }
        else
        {
            $this->load->view('admin/common/header', $data);
            $this->load->view('admin/common/upload_success');
            $this->load->view('admin/common/footer');
        }
    }
}

这就是我得到的

( ! ) Fatal error: Call to undefined method CI_Upload::do_image_upload() in C:\wamp\www\aguasprofundas\application\controllers\admin\upload_image.php on line 43
Call Stack
#   Time    Memory  Function    Location
1   0.0000  148816  {main}( )   ..\index.php:0
2   0.0020  184888  require_once( 'C:\wamp\www\aguasprofundas\system\core\CodeIgniter.php' )    ..\index.php:202
3   0.0320  1717016 call_user_func_array:{C:\wamp\www\aguasprofundas\system\core\CodeIgniter.php:359} ( )   ..\CodeIgniter.php:359
4   0.0320  1717208 Upload_image->do_image_upload( )    ..\CodeIgniter.php:359

我一直在阅读一些关于区分大小写的帖子,但我认为情况并非如此。任何帮助都将受到欢迎。

谢谢!

【问题讨论】:

    标签: codeigniter uploading


    【解决方案1】:

    if ( ! $this-&gt;upload-&gt;do_image_upload())

    应该是

    if ( ! $this-&gt;upload-&gt;do_upload())

    【讨论】:

    • 不幸的是,我遇到了完全相同的问题。这次引用 do_upload() 而不是 do_image_upload(): Fatal error: Call to undefined method CI_Upload::do_upload() in
    • 您是否将 CI_Upload 扩展为 MY_Upload? do_upload() 应该是正确的调用。 github.com/bcit-ci/CodeIgniter/blob/master/system/libraries/…
    • 0 反对票 接受 感谢 Wing!!!!我真的很感谢你的帮助。从“bcit-ci/CodeIgniter”更新我的加载文件并重命名:do_image_upload() 和 do_document_upload() 函数为 do_upload() 解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 2012-01-06
    • 2014-07-20
    相关资源
    最近更新 更多