【问题标题】:Codeigniter - Facing issue with multiple thumbnail creationCodeigniter - 面临创建多个缩略图的问题
【发布时间】:2015-10-01 06:09:43
【问题描述】:

我正在玩Codeigniter图片上传库并一次上传多张图片,我正在用拇指上传原始图片。

现在如果我要上传三张图片,它会将所有三张原始图片上传到这个文件夹:project-images。和缩略图去thumbs 文件夹。一切都很好,但我在thumbs 文件夹中只得到一张图像。 2 没有在thumbs 文件夹中上传。

我当前的代码有什么问题。

有什么想法吗?

if(!empty($_FILES['userfile'])){
    $name_array = array();
    $count = count($_FILES['userfile']['size']);
    foreach($_FILES as $key => $value)
        for ($s=0; $s<=$count-1; $s++)
        {
            // Original Image Upload - Start
            $_FILES['userfile']['name'] = $value['name'][$s];
            $_FILES['userfile']['type'] = $value['type'][$s];
            $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
            $_FILES['userfile']['error'] = $value['error'][$s];
            $_FILES['userfile']['size'] = $value['size'][$s];
            $config['upload_path'] = './public/images/project-images/';
            $config['allowed_types'] = 'gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG';
            $config['max_size'] = '10000';
            $CI->load->library('upload', $config);
            $CI->upload->do_upload();
            $data = $CI->upload->data();
            $name_array[] = $data['file_name'];
            // Original Image Upload - End

            // Thumbnail Image Upload - Start
            $config2['image_library'] = 'gd2';
            $config2['source_image'] = $CI->upload->upload_path.$CI->upload->file_name;
            $config2['new_image'] = './public/images/project-images/thumbs';
            $config2['maintain_ratio'] = TRUE;
            $config2['create_thumb'] = TRUE;
            $config2['thumb_marker'] = '_thumb';
            $config2['width'] = 370;
            $config2['height'] = 200;
            $CI->load->library('image_lib',$config2);

            if(!$CI->image_lib->resize()){
                $CI->session->set_flashdata('errors', $CI->image_lib->display_errors('', ''));
            }

            // [ MAIN IMAGE ]
            $config['image_library'] = 'gd2';
            $config['source_image'] = $CI->upload->upload_path.$CI->upload->file_name;
            $config['maintain_ratio'] = TRUE;
            $CI->load->library('image_lib',$config);
            // Thumbnail Image Upload - End
        }
    return $name_array;
}

【问题讨论】:

    标签: php codeigniter codeigniter-2


    【解决方案1】:

    最后我通过在$CI-&gt;image_lib-&gt;resize()之前添加此代码得到了解决方案:

    $CI->image_lib->clear();
    $CI->image_lib->initialize($config2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-09
      • 2011-02-25
      • 2011-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      相关资源
      最近更新 更多