我已经在其他地方使用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
我一直在阅读一些关于区分大小写的帖子,但我不认为是这种情况。任何帮助都将受到欢迎。
谢谢!
答案 0 :(得分:2)
if ( ! $this->upload->do_image_upload())
应该是
if ( ! $this->upload->do_upload())