【发布时间】:2018-06-25 22:26:07
【问题描述】:
我遇到了使用 codeigniter image_lib 创建多个图像的问题。这是我的代码。问题是只有原始图像正在上传,而不是其他图像,如数组中定义的拇指、中、大。
我的控制器代码是:
function do_upload() {
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path,
'max_size' => 2000
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$image_sizes = array(
'thumb' => array(150, 100),
'medium' => array(300, 300),
'large' => array(800, 600)
);
$this->load->library('image_lib');
foreach ($image_sizes as $resize) {
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '-' . $resize[0] . 'x' .
$resize[1],
'maintain_ration' => true,
'width' => $resize[0],
'height' => $resize[1]
);
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
}
}
【问题讨论】:
标签: php codeigniter image-uploading