Я пытаюсь загрузить 3 изображения и изменить их размер каждый раз, когда я загружаю изображение. Я помещаю имя изображения в массив images
, однако в конце метода, когда я print_r($images)
, я получаю тольконазвание последнего загруженного изображения, может кто-нибудь сказать мне, почему это?
Вот мой код,
// lets get rid of any old configs
$secondaryConfig['upload_path'] = './media/uploads/news/';
$secondaryConfig['allowed_types'] = 'gif|jpg|png';
$secondaryConfig['max_size'] = '4000';
$secondaryConfig['max_width'] = '230';
$secondaryConfig['max_height'] = '120';
$secondaryManipulationConfig['image_library'] = 'gd2';
$secondaryManipulationConfig['create_thumb'] = FALSE;
$secondaryManipulationConfig['maintain_ratio'] = TRUE;
$secondaryManipulationConfig['width'] = 132;
$secondaryManipulationConfig['height'] = 80;
//image_1
$this->upload->initialize($secondaryConfig);
if (!$this->upload->do_upload('image_1'))
{
$data['error_image_1'] = $this->upload->display_errors();
$this->template->build('admin/news/edit', $data);
return;
}
else
{
$image = $this->upload->data();
$images[] = $image['file_name'];
$this->image_lib->initialize($secondaryManipulationConfig);
$secondaryManipulationConfig['source_image'] = './media/uploads/news/'.$image['file_name'];
if (!$this->image_lib->resize())
{
$data['error_image_1'] = $this->image_lib->display_errors();
$this->template->build('admin/news/edit', $data);
return;
}
}
$this->upload->initialize($secondaryConfig);
if (!$this->upload->do_upload('image_2'))
{
$data['error_image_2'] = $this->upload->display_errors();
$this->template->build('admin/news/edit', $data);
return;
}
else
{
$image = $this->upload->data();
$images[] = $image['file_name'];
$this->image_lib->initialize($secondaryManipulationConfig);
$secondaryManipulationConfig['source_image'] = './media/uploads/news/'.$image['file_name'];
if (!$this->image_lib->resize())
{
$data['error_image_2'] = $this->image_lib->display_errors();
$this->template->build('admin/news/edit', $data);
return;
}
}
//image_3
$this->upload->initialize($secondaryConfig);
if (!$this->upload->do_upload('image_3'))
{
$data['error_image_3'] = $this->upload->display_errors();
$this->template->build('admin/news/edit', $data);
return;
}
else
{
$image = $this->upload->data();
$images[] = $image['file_name'];
$this->image_lib->initialize($secondaryManipulationConfig);
$secondaryManipulationConfig['source_image'] = './media/uploads/news/'.$image['file_name'];
if (!$this->image_lib->resize())
{
$data['error_image_3'] = $this->image_lib->display_errors();
$this->template->build('admin/news/edit', $data);
return;
}
}