Codeigniter创建缩略图不工作


Codeigniter Create Thumbnail Not Working?

我有2个用于图像上传和拇指创建的编码器函数。图片上传功能正常,但创建拇指功能不工作。我不知道我的函数出了什么问题?

function uploaded() //upload  function
{           
            $config['upload_path'] ='./uploads/';
            $config['allowed_types'] ='jpeg|jpg|png|gif|bmp|JPEG|JPG|PNG|GIF|BMP|doc|docx|xlsx|txt';
            $config['max_size'] = $this->config->item('max_upload_size');
            $filename = strtolower($this->friendly($_FILES['image']['name']));
            $config['file_name'] = $filename;
            $config['remove_spaces'] = TRUE;
            $this->load->library('upload', $config);
            if ($this->upload->do_upload('image'))
            {
            $this->data['file'] = $this->upload->data(); 
            $this->thumb($filename);
            return true; 
            }
}

创建拇指函数

function thumb($filename)
{
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/'.$filename.'.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']    = 75;
$config['height']   = 50;
$config['new_image'] = './uploads/thumb/'.$filename;
$this->load->library('image_lib', $config); 
$this->image_lib->initialize($config);
$this->image_lib->resize();
}

稍微修改一下你的代码。

上传功能更改

function uploaded() //upload  function
{           
            $config['upload_path'] ='./uploads/';
            $config['allowed_types'] ='jpeg|jpg|png|gif|bmp|JPEG|JPG|PNG|GIF|BMP|doc|docx|xlsx|txt';
            $config['max_size'] = $this->config->item('max_upload_size');
            //$filename = strtolower($this->friendly($_FILES['image']['name'])); #your filename has been commented
            $filename = preg_replace('/[^a-zA-Z0-9_.]/', '_', $file_name); //replace special char including whitespace with _
            $filename = preg_replace('/_+/', '_', $file_name); //replace multiple _ with single one.
            $config['file_name'] = $filename;
            $config['remove_spaces'] = TRUE;
            $this->load->library('upload', $config);
            if ($this->upload->do_upload('image'))
            {
            $this->data['file'] = $this->upload->data(); 
            $this->thumb($filename);
            return true; 
            }
}

拇指功能变化

function thumb($filename)
{
$config['image_library'] = 'gd2';
//$config['source_image'] = './uploads/'.$filename.'.jpg';  #no need to make it static as you are allowing multiple extensions in allowed_types.
$config['source_image'] = './uploads/'.$filename;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']    = 75;
$config['height']   = 50;
$config['new_image'] = './uploads/thumb/'.$filename;
$this->load->library('image_lib', $config); 
$this->image_lib->initialize($config);
$this->image_lib->resize();
}