我正在使用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;
}
答案 0 :(得分:1)
最后我通过在$CI->image_lib->resize()
之前添加此代码来获得解决方案:
$CI->image_lib->clear();
$CI->image_lib->initialize($config2);