0

嘿伙计们,我有这个问题,我花了 4-5 个小时寻找解决方案这是我的代码

$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”文件夹中没有创建任何拇指。如果您有任何建议,请给我一些帮助。谢谢!

4

1 回答 1

1

您可以使用 Stream APi 来开发您的模块。顺便说一句,我使用 PyroCMS 并且刚刚完成了一个新模块,并且我使用 codeigniter lib 毫无问题地创建了 thumb。你的代码是正确的,我唯一可以建议你的是以这种方式分离 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);

这样你应该没有任何问题。如果它不起作用尝试将主图像和拇指分开,您可以创建第一个图像,然后创建具有两个分离功能的拇指。

于 2012-12-09T14:33:02.997 回答