$config = array(
'upload_path' => './uploads/menus',
'allowed_types' => 'gif|jpg|jpeg|png',
'max_size' => '15000'
);
$this->upload->initialize($config);
if ($this->upload->do_upload('image'))
{
$image_data = $this->upload->data();
$thumbnail = 'thumb_' . $image_data['file_name'];
$thumb['image_library'] = 'gd2';
$thumb['source_image'] = $image_data['full_path'];
$thumb['create_thumb'] = TRUE;
$thumb['thumb_marker'] = '';
$thumb['new_image'] = $image_data['file_path'] . 'thumbs/' . $thumbnail;
$thumb['maintain_ratio'] = TRUE;
$thumb['width'] = 90;
$thumb['height'] = 90;
$this->load->library('image_lib', $thumb);
if($this->image_lib->resize())
{
$img_details = array(
'menu_id' => $this->db->insert_id(),
'full_path' => $image_data['full_path'],
'image_name' => $image_data['file_name'],
'thumb_path' => $thumb['new_image'],
'thumb_name' => $thumbnail,
);
$upload = $this->db->insert('menus_images', $img_details);
return $upload;
}
}
我正在使用PyroCMS,我正在开发一个模块,我需要上传图像。到目前为止这么好,我的问题是: 图像上传,调整大小检查没有问题,在db中插入正确的数据,但在“thumbs”文件夹中不创建任何拇指。 如果您有任何建议,请给我一些帮助。 谢谢!
答案 0 :(得分:1)
您可以使用Stream APi开发模块。顺便说一句,我使用PyroCMS,我刚刚完成了一个新模块,我使用codeigniter lib创建了没有问题的拇指。 你对semms的编码是正确的,我唯一能建议你的是以这种方式分离image_lib的加载和它的初始化:
$this->load->library('image_lib');
$thumbnail = 'thumb_' . $image_data['file_name'];
$thumb['image_library'] = 'gd2';
$thumb['source_image'] = $image_data['full_path'];
$thumb['create_thumb'] = TRUE;
$thumb['thumb_marker'] = '';
$thumb['new_image'] = $image_data['file_path'] . 'thumbs/' . $thumbnail;
$thumb['maintain_ratio'] = TRUE;
$thumb['width'] = 90;
$thumb['height'] = 90;
$this->image_lib->initialize($thumb);
这样你就不会有任何问题。 如果它不起作用尝试分离主图像和拇指,您可以创建第一个图像,然后使用两个分离功能创建拇指。