0

I'm trying to resize pre-uploaded images and then send them to another server with FTP, but it doesnt seems to be working. The uploading is working fine, the ftp is working fine too but whenever I download the image and check the size it's just the same as the uploaded file.

This is my controller:

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();
        }

What I want to achieve is upload the image, resize and replace it and upload the resized image after that.

Help is very much appreciated!

13
  • set log_threshold to 4 in config, check the logs to see what happens Commented May 18, 2015 at 17:52
  • @Ara I have done so but my logs folder is empty. I removed the images and the product and tried re-adding them but the log remains empty. Commented May 18, 2015 at 18:07
  • have you set the logs folder permissions to 777 (read&write for all)? Commented May 18, 2015 at 18:10
  • @Ara Yes I do, but won't permissions 644 be enough already? I had 644 before but changed it to 777 now, still nothing. Commented May 18, 2015 at 18:14
  • 666 is for writable files, 777 for writable folders and i mean the logs folder which is inside application folder (not talking about file), if you are sure it is 777 , check your config and make sure about $config['log_path'] = ''; ('' = default) and log_threshold = 4 Commented May 18, 2015 at 18:17

1 Answer 1

1

Final Edit:

Used initialize to pass the configs instead of passing them directly to load->library:

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();
    }
Sign up to request clarification or add additional context in comments.

7 Comments

My ftp is being executed just fine so that cannot be the case. Same for my upload, the image IS being uploaded.
This seemed to have fixed my problem, I suppose the problem being I had to add the : $this->image_lib->initialize($config); I'm not going to load the library inside my construct as there are only 2 functions inside there which require it.
Im still wondering how it got fixed because as far as I know the $this->image_lib->clear(); is only used when inside a loop that can have different values, and the $this->image_lib->initialize($config) should be the same as $this->load->library('image_lib', $config); if I am correct?
@killstreet good to hear that, suggested adding it to construct to see if it fails to load in there too
if you dont use it in construct no need to clear() , did you try $this->load->library('image_lib'); $this->image_lib->initialize($config); ? (changed load with the clear)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.