那么我有以下问题:我正在使用 CodeIgniter 2.1.3 并且想要上传图像并创建两个缩放图像。一个调整到大约 50x50 的大小,一个调整到大约 200x200。
上传效果很好。
但是当我想调整大小时,会发生以下错误: 无法保存图像。请确保图像和文件目录是可写的。
我已将服务器上的权限设置为 777,但它仍然无法计算
这是类的代码:
public function uploadimage()
{
$head = array('title' => 'Upload Image');
$error = array('error' => '');
$this->load->view('head',$head);
$this->load->view('imageUpload', $error);
$this->load->view('footer');
}
public function changeimage()
{
$config = array();
$config['upload_path'] = 'img/Upload';
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp';
$config['max_size'] = '100';
$config['max_width'] = '200';
$config['max_height'] = '200';
$config['overwrite'] = TRUE;
$config['file_name'] = md5($this->session->userdata('username')).".png";
$head = array('title' => 'Upload Image');
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('head',$head);
$this->load->view('imageUpload', $error);
$this->load->view('footer');
}
else
{
$uploaddata = $this->upload->data();
//Create Thumb
$config2 = array();
$config2['image_library'] = 'gd';
$config2['source_image'] = $uploaddata['full_path'];
$config2['maintain_ratio'] = TRUE;
$config2['width'] = 50;
$config2['height'] = 50;
$config2['new_image'] = '/~3612546/DateSite/img/ProfileThumbs/'.$uploaddata['file_name'];
$this->image_lib->initialize($config2);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
//Create resized original image so images < 200x200 get resized to get as close to 200x200
$config3 = array();
$config3['image_library'] = 'gd';
$config3['source_image'] =$uploaddata['full_path'];
$config3['maintain_ratio'] = TRUE;
$config3['width'] = 200;
$config3['height'] = 200;
$config3['new_image'] = '/~3612546/DateSite/img/ProfileImages/'.$uploaddata['file_name'];
$this->image_lib->initialize($config3);
if ( ! $this->image_lib->resize())
{
echo $uploaddata['full_path'];
echo $this->image_lib->display_errors();
}
}
}