【发布时间】:2016-02-05 12:27:04
【问题描述】:
我目前正在使用 codeigniter 创建一个程序,我想在其中上传图像并将其作为 blob 保存到数据库。问题是当我尝试上传图片时,我收到了这个错误
The path to the image is not correct.
Your server does not support the GD function required to process this type of image.
这是我在控制器中的代码:
public function do_upload() {
if($this->session->userdata('logged_in')) {
//print_r($_FILES);
$config = array(
'upload_path' => './public/img/uploads',
'upload_url' => base_url().'public/img/uploads',
'allowed_types' => 'gif|jpg|png|jpeg',
//'overwrite' => TRUE,
'max_size' => '1000KB',
'max_width' => '1024',
'max_height' => '768',
//'encrypt_name' => true,
);
$this->load->library('upload', $config);
//for($i=0; $i<count($_FILES['userfile']['name']); $i++) {
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('v_page/header_view');
$this->load->view('v_document/upload_error', $error);
$data['folderName'] = $this->dropdown->get_folder_details();
$data['departmentName'] = $this->dropdown->get_department_details();
$this->load->view('v_document/upload_view', $data);
$this->load->view('v_page/footer_view');
}
else {
$upload_data = $this->upload->data();
$this->_createThumbnail($upload_data['file_name']);
$data['thumbnail_name'] = $upload_data['raw_name']. '_thumb' .$upload_data['file_ext'];
$file_array = array(
'image' => "",
'image_name' => $upload_data['file_name'],
//'description' => "",
'date_created' => date('Y-m-d H:i:s', now()),
'date_modified' => date('Y-m-d H:i:s', now()),
'size' => $upload_data['file_size'],
'type' => $upload_data['image_type'],
'width' => $upload_data['image_width'],
'height' => $upload_data['image_height'],
);
$this->load->database();
$this->db->insert('tbl_image', $file_array);
$data = array('upload_data' => $this->upload->data());
$this->load->view('v_document/upload_success', $data);
}
//}
}
else {
redirect('login', 'refresh');
}
}
public function _createThumbnail($filename) {
$config['image_library'] = "gd2";
$config['source_image'] = "uploads/" .$filename;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = "80";
$config['height'] = "80";
$this->load->library('image_lib',$config);
if(!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
}
图片已成功上传,但 blob 无效。
【问题讨论】:
标签: codeigniter blob