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

时间:2015-06-16 04:48:30

标签: php codeigniter

我已应用以下代码。但没有找到任何解决方案。如何将支持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.

2 个答案:

答案 0 :(得分:0)

我现在发现了这个问题。我必须删除此代码。

pdftk

希望这也适用于其他人。

答案 1 :(得分:0)

我接受的几件事是

$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']