这是我的控制器
public function do_upload()
{
$propertyID = $this->uri->segment(3);
$this->load->helper('date');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['file_name'] = date('m-y-d-h-m-s')."_".$propertyID;
$name = $config['file_name'];
$this->load->library('upload', $config);
$this->load->model('user_model');
$prop['propertyID'] = $propertyID;
// looping $_FILES and create new one
foreach($_FILES['userfile'] as $key=>$val)
{
$i = 1;
foreach($val as $v)
{
$field_name = "file_".$i;
$_FILES[$field_name][$key] = $v;
$i++;
}
}
// delete the initial array, because we already have a new array
unset($_FILES['userfile']);
//error variables changed, from a string into an array
$error = array();
$success = array();
foreach($_FILES as $field_name => $file)
{
if ( ! $this->upload->do_upload($field_name))
{
$error[] = $this->upload->display_errors();
}
else
{
$success[] = $this->upload->data();
$this->thumb_nail($name);
$config12['image_library'] = 'gd2';
$config12['source_image'] = './uploads/'.$config['file_name'].'.jpg';
$config12['new_image'] = './uploads/medium/'.$config['file_name'];
$config12['create_thumb'] = TRUE;
$config12["thumb_marker"] = "";
$config12['maintain_ratio'] = TRUE;
$config12['width'] = 500;
$config12['height'] = 400;
$this->image_lib->clear();
$this->image_lib->initialize($config12);
$this->image_lib->resize();
$data = $this->upload->data();
$prop['imgName'] = $data['file_name'];
$this->user_model->addImage($prop);
}
}
if(count($error) > 0)
{
$data['error'] = implode('<br />',$error);
$data['profile'] = $this->user_model->get_profile_image($propertyID);
$data['photos'] = $this->user_model->get_property_images_by_ID($propertyID);
$data['main_content'] = 'manage_property_images1';
$this->load->view('1_col', $data);
}
else
{
$data['profile'] = $this->user_model->get_profile_image($propertyID);
$data['photos'] = $this->user_model->get_property_images_by_ID($propertyID);
$data['main_content'] = 'manage_property_images1';
$this->load->view('1_col', $data);
}
}
如果我上传了单张图片,它会调整大小并将图像保存在正确的目录中。
但是如果我上传了多张图片,它只会调整第一张图片的大小。 我需要清除一些东西。有人可以帮忙吗
答案 0 :(得分:0)
尝试这样的方法来重置每个图像的图像库
//Create Thumbnail
$config['image_library'] = 'gd2';
$config['source_image'] = $data['full_path'];
$config['maintain_ratio'] = true;
$config['width'] = 1280;
$config['height'] = 400;
$this->load->library('image_lib'); //<----- SEE
$this->image_lib->initialize($config); //<----- SEE
if($this->image_lib->resize())
{
$this->image_lib->clear(); //<----- SEE
return true
}
它对我有用。