php – Codeigniter:无法为多个图像创建缩略图

我正在尝试一次上传多个图像(3)并为每个图像创建缩略图.但是我的代码上传了3张图片,只创建了1个缩略图(第1张图片缩略图).如何创建多个图像的缩略图
控制器:upload Image功能并创建缩略图功能

function uploadImage()
{
  if($this->validate()==TRUE) {
    $config['upload_path']   =   "images/uploads/";
    $config['allowed_types'] =   "gif|jpg|jpeg|png"; 
    $config['max_size']      =   "5000";
    $config['max_width']     =   "1907";
    $config['max_height']    =   "1280";

    $this->load->library('upload',$config);

    foreach ($_FILES as $key => $value) {

      if (!empty($value['tmp_name'])) {
        if ( ! $this->upload->do_upload($key)) {
          $error = array('error' => $this->upload->display_errors());
          //Failed display the errors
        }     
        else {
          //success
          $finfo=$this->upload->data();
          $this->_createThumbnail($finfo['file_name']);
          $data['uploadInfo'] = $finfo;
          $data['thumbnail_name'] = $finfo['raw_name']. '_thumb' .$finfo['file_ext']; 
        }
      }
    }
  }
}

//Create Thumbnail function
function _createThumbnail($filename)
{
  $config['image_library']    = "gd2";      
  $config['source_image']     = "images/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();
  }      
}

解决方法

根据此 link.对createthumbnail函数进行一些更改

代替

$这 – >负载>库( ‘image_lib’,$配置);
使用

$this->load->library('image_lib');
// Set your config up
$this->image_lib->initialize($config);
// Do your manipulation
$this->image_lib->clear();

新的createThumbnail函数

//Create Thumbnail function
function _createThumbnail($filename)
{
    $this->load->library('image_lib');
    // Set your config up
    $config['image_library']    = "gd2";      
    $config['source_image']     = "images/uploads/" .$filename;      
    $config['create_thumb']     = TRUE;      
    $config['maintain_ratio']   = TRUE;      
    $config['width'] = "80";      
    $config['height'] = "80";

    $this->image_lib->initialize($config);
    // Do your manipulation

    if(!$this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
    } 
    $this->image_lib->clear();     
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...