gd - Coordinator : GD library already installed on server but show Your server does not support the GD function required to process this type of image
问题描述
I already installed GD library on server but if I upload image with jpg,png,jpeg
image format then show error "Your server does not support the GD function required to process this type of image."
If GD library is installed then why show these type of error ?
$config['upload_path'] = $this->upload_path;
$config['allowed_types'] = $this->image_types;
$config['max_size'] = $this->allowed_file_size;
$config['max_width'] = $this->Settings->iwidth;
$config['max_height'] = $this->Settings->iheight;
$config['overwrite'] = FALSE;
$config['encrypt_name'] = TRUE;
$config['max_filename'] = 25;
$this->upload->initialize($config);
if (!$this->upload->do_upload('product_image')) {
$error = $this->upload->display_errors();
$this->session->set_flashdata('error', $error);
redirect("products/edit/" . $id);
}
$photo = $this->upload->file_name;
$data['image'] = $photo;
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $this->upload_path . $photo;
$config['new_image'] = $this->thumbs_path . $photo;
$config['maintain_ratio'] = TRUE;
$config['width'] = $this->Settings->twidth;
$config['height'] = $this->Settings->theight;
$this->image_lib->clear();
$this->image_lib->initialize($config);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
解决方案
您正在传递$this->upload->file_name
未知值。GD
库找不到您传递给$photo
验证的字符串/对象的图像格式和扩展名。
您应该使用$this->upload->data()
来捕获上传的图像值,如下所示。
$config = [
'upload_path' => $this->upload_path, // make sure you are adding tailing `/` in your upload path, else you should add `/` before joing the images below
'allowed_types' => $this->image_types,
'max_size' => $this->allowed_file_size,
'max_width' => $this->Settings->iwidth,
'max_height' => $this->Settings->iheight,
'overwrite' => false,
'encrypt_name' => true,
'max_filename' => 25
];
$this->load->library('upload', $config); // make sure you are loading the `upload` library, else it will load
$this->upload->initialize($config);
if($this->upload->do_upload('product_image')){
$uploaded_data = $this->upload->data(); // here you should collect the uploaded data
$data['image'] = $uploaded_data['file_name'];
$config = [
'image_library' => 'gd2',
'source_image' => $this->upload_path . $uploaded_data['file_name'],
'new_image' => $this->thumbs_path . $uploaded_data['file_name'],
'maintain_ratio' => true,
'width' => $this->Settings->twidth,
'height' => $this->Settings->theight,
'quality' => '100%',
];
$this->load->library('image_lib', $config);
$this->image_lib->initialize($config);
if ($this->image_lib->resize()){
return true;
}else{
return $this->image_lib->display_errors();
}
}else{
$this->session->set_flashdata('error', $this->upload->display_errors());
redirect("products/edit/" . $id);
}
推荐阅读
- spring - 引起:java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver - 微服务
- javascript - 带有服务器端数据表的空 ajax 返回
- android - Smack 4.2.4 版:资源限制 - 等待
- r - 使用 data.table 中的“:=”将值分配给子集上的多个列
- c# - 如何通过使用 linq 或反射比较 2 个列表来获取更新或修改的列表记录
- gnuradio - 关于我的 GNU Radio 源代码块的采样率
- asp.net-mvc - 允许 Dropzone js 仅上传 zip 文件
- c# - Microsoft 网络聊天机器人跨会话 C# 存储全局数据
- c# - 应用打开时 Xamarin Android 发送回登录
- javascript - 接收数据后异步/等待.map 错误?