我有以下问题: 我正在使用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();
}
}
}
答案 0 :(得分:0)
我真的不认为代字号对上传网址有好处:
/~3612546/DateSite/img/ProfileImages/
然后,你的所有网址都是大写/小写,将它们全部放到小写字样:
/~3612546/dateSite/img/profileimages/
最后发布了什么错误,你现在chmod 777上传文件夹,你是否只将777添加到dir或dir +他的所有内容? (这是重要的目录+他所有的内容到777)