CodeIgniter Forums
uploading an image then resizing it - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: uploading an image then resizing it (/thread-23566.html)



uploading an image then resizing it - El Forum - 10-14-2009

[eluser]elusid[/eluser]
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:

Code:
<?php

class Upload extends Controller {

    function Upload()
    {
        parent::Controller();
        $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);
                    }
                        else
                    {


                    $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);
                    $this->image_lib->resize();


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


Any helpful insights will be greatly appreciated. thanks!


uploading an image then resizing it - El Forum - 10-14-2009

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



uploading an image then resizing it - El Forum - 10-15-2009

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

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.


uploading an image then resizing it - El Forum - 10-15-2009

[eluser]elusid[/eluser]
On a further note I tested GD again using this script:

http://www.dagondesign.com/articles/checking-for-gd-support-on-your-server/

and everything was A-OK.


uploading an image then resizing it - El Forum - 10-15-2009

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