Image_lib路径名错误,服务器不支持GD功能

Image_lib path name error and server does not support the GD function

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

"The path to the image is not correct.Your server does not support the GD function required to process this type of image." 但是在 $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();  
                        }

GD 是一个处理图像处理的 php 扩展。您正在加载的库需要它才能工作。 广东: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 集