如何在 Codeigniter 的库中调用助手?
我的代码:
class Upload
{
protected $ci;
function __construct()
{
$this->ci =& get_instance();
// Load helper
$this->ci->load->helper('form');
}
function upload_file($file, $file_types = 'gif|jpg|png', $max_size = 1000, $max_width = 200, $max_height = 300)
{
// Set params
$config['upload_path'] = 'attached-files';
$config['allowed_types'] = $file_types;
$config['max_size'] = $max_size;
// Check if max_width is set equals to it is a image
if(isset($max_width))
{
$config['max_width'] = $max_width;
$config['max_height'] = $max_height;
}
// Try to upload the file
if (!$this->ci->upload->do_upload($file))
{
$data['profile_image_upload'] = array('error' => $this->ci->upload->display_errors());
}
else
{
$data['upload_data'] = $this->ci->upload->data();
}
return $data;
}
我正在尝试构建一个通用库,当我想上传文件时调用它,如果它是 pdf、图像或其他文件则独立。
但我收到以下代码错误:
if (!$this->ci->upload->do_upload($file))
错误消息: 调用未定义的方法 Upload::do_upload()