如何将支持 gd 库添加到服务器



我应用了以下代码。但没有找到任何解决方案。如何将支持 gd 库添加到服务器。

public function addreqdoctor()
{
    if($_FILES['userfile']['name']){
        $ext = end(explode(".", $_FILES['userfile']['name']));
        $new_name = time()."_".rand(1,10000).'.'.$ext;
        $basic['picture'] =  $new_name;
        $config['upload_path'] = './doctors/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['file_name']     =  $new_name;
        $this->load->library('upload', $config);
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
        }else{
            $this->upload->do_upload();
            $configs['image_library'] = 'gd2';
            $configs['source_image']    = './doctors/'.$new_name;
            $config['new_image'] = './doctors/thumbs/'.$image_name;
            $configs['create_thumb'] = TRUE;
            $configs['maintain_ratio'] = TRUE;
            $configs['width']   = 80;
            $configs['height']  = 70;
            $this->load->library('image_lib');
            $this->image_lib->initialize($configs);
            $this->image_lib->clear();
            if ( ! $this->image_lib->resize())
            {
                echo $this->image_lib->display_errors();die;
            }
            else{
                $this->image_lib->resize();
            }
        }
    }

我发现了这个错误。上传文件后,浏览器中会出现此错误。

Your server does not support the GD function required to process this type of image.

我发现的几件事是

$config['new_image'] = './doctors/thumbs/'.$image_name;

应该是

$configs['new_image'] = './doctors/thumbs/'.$image_name;

并尝试更改此内容

$configs['maintain_ratio'] = TRUE;

$configs['maintain_ratio'] = FALSE;

Upload_Resize

另外,当想要获取图像名称时,请使用$this->upload->data();

$upload_info = $this->upload->data();
$configs['source_image']    = './doctors/'. $upload_info['file_name'];
$configs['new_image'] = './doctors/thumbs/'. $upload_info['file_name']

我现在发现了问题。我只需要删除此代码。

  $this->image_lib->clear();

希望这也对其他人有用。

最新更新