Welcome Guest, Not a member yet? Register   Sign In
uploading an image then resizing it

Hello folks,

I'm a codeigniter noobie and have been smackin' my head on the desk over this one piece of code... I've done my research here and on google,etc looking for a solution to no avail... so essentially what i'm trying to do is upload an image file with a a form and then make a copy of it and resize that image to a thumbnail. The way my code is now i'm not getting any error messages and the upload process seems to work fine. I didnt have GD installed at first and I fixed that and its loading fine after checking phpinfo();

here is my upload controller:


class Upload extends Controller {

    function Upload()
        $this->load->helper(array('form', 'url'));

    function index()

                $data['title'] = "title";
                $data['heading'] = "title";
        $this->load->view('upload_view', $data, array('error' => ' ' ));

    function do_upload()
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '500';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
                $config['remove_spaces'] = 'TRUE';
                $config['encrypt_name'] = 'TRUE';

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

                 //else if loop displays success or error
        if ( ! $this->upload->do_upload())
        $data['title'] = 'Uh Oh! Error Uploading';
                $data['heading'] = 'Error Uploading File';

                //displays error in heading but too big
                //$data['heading'] = $this->upload->display_errors();

                  //$error = array('error' => $this->upload->display_errors());

                        $this->load->view('upload_view', $data);

                    $data = array('upload_data' => $this->upload->data());
                    //$data['file_name'] = array('upload_data' => 'file_name');

                    $upload_data = $this->upload->data();

                    $config['image_library'] = 'gd2';                    
                    $config['source_image'] = './uploads/'.$upload_data['file_name'];
                    $config['create_thumb'] = TRUE;
                    $config['maintain_ratio'] = TRUE;
                    $config['width'] = 75;
                    $config['height'] = 50;

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

                $data['title'] = "It worked!";
                $data['heading'] = 'Success!!';
                $this->load->view('success_view', $data);

Any helpful insights will be greatly appreciated. thanks!

try setting source_image to an absolute path:
$config['source_image'] = $upload_data['full_path'];

[quote author="bretticus" date="1255599561"]try setting source_image to an absolute path:
$config['source_image'] = $upload_data['full_path'];

Hi Bretticus,

thanks for the advice. Unfortunately that did not work either. The file is uploaded with no problems but still no thumbnail is created.

On a further note I tested GD again using this script:


and everything was A-OK.

Your setup looks correct, did you check your logs to see if there's any hints being logged?

Theme © iAndrew 2016 - Forum software by © MyBB