我的控制器:如何上傳圖片,調整其大小以及如何在codeigniter中顯示調整大小的圖片?
public function addgalleryProcess()
{
$height = $this->input->POST('height');
$width = $this->input->POST('width');
$config['upload_path'] = './assets/images/gallery';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '';
$config['max_height'] = '';
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/addgallery', $error);
}
else
{
$upload_data = $this->upload->data();
//resize:
$config1['image_library'] = 'gd2';
$config1['source_image'] = $upload_data['full_path'];
$config1['maintain_ratio'] = TRUE;
$config1['create_thumb'] = TRUE;
$config1['width'] = $width;
$config1['height'] = $height;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
$this->adminModel->galleryimages($upload_data);
$this->load->view('admin/homeView');
}
我的模型:
public function galleryimages($image_data = array())
{
$data = array(
'image' => $image_data['file_name'],
);
$this->db->insert('gallery', $data);
}
這裏像正常工作和上傳,但調整不工作。我必須顯示指定寬度和高度的已調整大小的圖像。我是新來的。 預先感謝。