Codeigniter 上传文件并调整大小

Codeigniter upload file and resize

我正在尝试调整预上传图像的大小,然后使用 FTP 将它们发送到另一台服务器,但它似乎不起作用。上传工作正常,ftp 也工作正常,但每当我下载图像并检查大小时,它与上传的文件一样。

这是我的控制器:

if ($this->upload->do_upload())
        {
            $data = $this->upload->data();
            $image = $data['file_name'];

            $this->load->library('image_lib');

            $config['image_library'] = 'gd2';
            $config['source_image'] = './uploads/devices/'.$image;
            $config['maintain_ratio'] = TRUE;
            $config['width']    = 400;
            $config['height']   = 300;

            $this->load->library('image_lib', $config);
            $this->image_lib->resize();

            $localPath = './uploads/devices/'.$image;
            $remotePath = 'webspace/httpdocs/uploads/devices/'.$image;

            $this->load->library('ftp');
            $config['hostname'] = '';
            $config['username'] = '';
            $config['password'] = '';
            $config['port']     = 21;
            $config['passive']  = TRUE;
            $this->ftp->connect($config);
            $this->ftp->upload($localPath, $remotePath);
            $this->ftp->close();
        }

我想要实现的是上传图片,调整大小并替换它,然后上传调整大小的图片。

非常感谢您的帮助!

最终编辑:

使用初始化来传递配置,而不是直接将它们传递给加载->库:

if ($this->upload->do_upload())
    {
        $data = $this->upload->data();
        $image = $data['file_name'];

        $config['image_library'] = 'gd2';
        $config['source_image'] = './uploads/devices/'.$image;
        $config['maintain_ratio'] = TRUE;
        $config['width']    = 400;
        $config['height']   = 300;

        $this->load->library('image_lib');
        $this->image_lib->initialize($config);

        $this->image_lib->resize();

        $localPath = './uploads/devices/'.$image;
        $remotePath = 'webspace/httpdocs/uploads/devices/'.$image;

        $this->load->library('ftp');
        $config['hostname'] = '';
        $config['username'] = '';
        $config['password'] = '';
        $config['port']     = 21;
        $config['passive']  = TRUE;
        $this->ftp->connect($config);
        $this->ftp->upload($localPath, $remotePath);
        $this->ftp->close();
    }