代码之家  ›  专栏  ›  技术社区  ›  Ramanand Vijayvargiya

协调器:服务器上已安装GD库,但表明您的服务器不支持处理此类映像所需的GD功能

gd
  •  0
  • Ramanand Vijayvargiya  · 技术社区  · 6 年前

    我已安装 图形处理函数库 在服务器上,但如果使用 jpg,png,jpeg 图像格式然后显示错误 "Your server does not support the GD function required to process this type of image." 如果安装了GD库,为什么要显示这些类型的错误?

    $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();
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Anfath Hifans    6 年前

    你通过了 $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);
    }