我一直在嘗試上傳和調整圖像大小。上傳似乎終於有效,但不是調整大小。Codeigniter文件調整上傳
在我的構造函數中我加載庫
$this->load->library('image_lib');
,然後在我的功能我打電話調整大小並上傳
$this->require_auth();
$img = $this->input->post('photo1');
$config['upload_path'] = './HTML/files/';
$config['file_name'] = 'photo1.jpg';
$config['file_path'] = './HTML/files/photo1.jpg';
$config['max-size'] = 2000;
$config['image_library'] = 'gd2';
$config['source_image'] = $config['file_path'];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 549;
$config['height'] = 549;
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['new_image'] = $config['file_path'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->load->library('upload', $config);
if (! $this->upload->do_upload('photo1')){
$error = array('error' => $this->upload->display_errors());
var_dump($error);
}else{
$this->blog_model->editServiceImg1($config['file_path']);
redirect('/blog');
}
我也試過這種
$this->require_auth();
$img = $this->input->post('service_photo1');
$config['upload_path'] = './HTML/files/';
$config['file_name'] = 'service_photo1.jpg';
$config['file_path'] = './HTML/files/service_photo1.jpg';
$config['max-size'] = 2000;
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
if (! $this->upload->do_upload('service_photo1')){
$error = array('error' => $this->upload->display_errors());
var_dump($error);
}else{
$config['image_library'] = 'gd2';
$config['source_image'] = $config['file_path'];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 549;
$config['height'] = 549;
$config['new_image'] = $config['file_path'];
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->blog_model->editServiceImg1($config['file_path']);
redirect('/blog');
}
有什麼我失蹤?我已經嘗試在初始上傳後調整大小,這似乎也無能爲力。任何幫助將非常感激。
您是否嘗試在上傳圖片之前調整大小? – Xrymz 2014-10-11 14:55:23
@LionKing不幸的是,它仍然不想工作。 – zazvorniki 2014-10-11 14:57:29
@Xrymz,是的,那正是我想要完成的。 – zazvorniki 2014-10-11 14:57:54