【问题标题】:Image_lib path name error and server does not support the GD functionImage_lib 路径名错误,服务器不支持 GD 功能
【发布时间】:2017-02-13 10:10:57
【问题描述】:

我正在尝试上传图片然后调整它的大小 然后出现错误

“图像的路径不正确。您的服务器不支持处理此类图像所需的 GD 功能。” 但在 $config['source_image'] = './production/images/'.$id_akun.'jpg'; 是我从 'upload_path' => "./production/images/" 的路径, 那为什么我的路径不正确? 这是我在控制器中的功能

                $id_akun=29;
                    $config = array(
                    'upload_path'  => "./production/images/",
                    'allowed_types' => "jpg",
                    'file_name' => $id_akun,
                    'overwrite' => true,
                    'max_size' => "2048",
                    'max_height' => "768",
                    'max_width' => "1024"
                    );
                    $this->upload->initialize($config);

                    if($this->upload->do_upload('userfile'))
                        {
                    $data = array(
                        'id' => $id_akun, 
                        'foto' => $this->upload->file_name
                        );
                        $this->User_model->upload($id_akun,$data);
                        $config['image_library'] = 'gd2';
                        $config['source_image'] = './production/images/'.$id_akun.'jpg';
                        $config['create_thumb'] = TRUE;
                        $config['maintain_ratio'] = TRUE;
                        $config['width']         = 220;
                        $config['height']       = 220;
                        $config['create_thumb'] = TRUE;
                        $this->image_lib->clear();
                        $this->image_lib->initialize($config);
                        $this->image_lib->resize();

                        $er=$this->image_lib->display_errors();
                        echo json_encode($er);
                        exit();  
                        }

【问题讨论】:

    标签: codeigniter codeigniter-3


    【解决方案1】:

    GD 是一个处理图像操作的 php 扩展。您正在加载的库需要它才能工作。 GD:http://php.net/manual/en/book.image.php

    如果您无法直接访问服务器,那您有点不走运,除非您可以让托管服务提供商为您提供扩展。

    如果你有服务器及其在 linux 上,你可以使用包管理器来安装它(作为 root 用户,或者使用 sudo)

    CentOS / RHEL 将是: yum install php-gd

    Ubuntu: apt-get install php-gd

    安装这些扩展后,您需要重新启动网络服务器以加载更新的 php.ini 文件。

    除此之外,使用./ 开始您的路径可能没有帮助,请在开始时删除.。我还建议确保文件夹路径从 web-root 退出,并且您在文件夹上设置了正确的权限,如果服务器是 linux 并且网络服务器拥有目录和文件的所有权,请确保您设置了正确的 chmod

    【讨论】:

    • 我正在使用本地计算机 windows 服务器并包含扩展名 php_gd2,我正在尝试删除 .在路径中但仍然相同的错误
    • 错误是没有找到GD,所以它不能做你要求它做的图像处理
    • 我正在检查 phpinfo GD 支持已启用
    • 我正在更改路径名并成功
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2013-05-06
    • 2021-06-15
    • 1970-01-01
    • 2023-01-07
    相关资源
    最近更新 更多