我正在尝试上传图像并调整其大小,并制作一个较小的副本。但它不会进行第二次调整大小。但它返回“真”。
我发现了更多关于它的问题,但他们没有做到这一点,建议如下:
$this->image_lib->clear();
在每次调整大小之前添加- 每次调整大小时不要加载库
- 使您的目录可写 (777)
我认为这不是我的代码的问题。
如果我遗漏了什么,请告诉我。
private function upload_image($id)
{
$config_1['upload_path'] = './public/img/news/';
$config_1['allowed_types'] = 'jpg|png';
$config_1['file_name'] = 'news_item_'.$id.'.jpg';
$config_1['overwrite'] = TRUE;
$config_1['max_size'] = '900';
$config_1['max_width'] = '5000';
$config_1['max_height'] = '5000';
$this->load->library('upload', $config_1);
if ( ! $this->upload->do_upload('image'))
{
$image_data = $this->upload->data();
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $image_data['full_path'];
$config['maintain_ratio'] = TRUE;
$config['quality'] = 75;
if($image_data['image_width'] > 2000){
$config['width'] = 2000;
$config['height'] = 1500;
}
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize()){echo $this->image_lib->display_errors();}
$this->image_lib->clear();
//thumb
$config['image_library'] = 'gd2';
$config['source_image'] = $image_data['full_path'];
$config['new_image'] = './public/img/news/thumb/news_item_'.$id.'.jpg';
$config['maintain_ratio'] = TRUE;
$config['quality'] = 75;
$config['width'] = 650;
$config['height'] = 500;
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize()){echo $this->image_lib->display_errors();}
$this->image_lib->clear();
}
}
解决方案
就是这样,该死的。! _ atif ( ! $this->upload->do_upload('image'))
不应该在那里。它现在可以工作了谢谢大家!