Welcome Guest, Not a member yet? Register   Sign In
Image Upload
#1

[eluser]carlhussey[/eluser]
Hey Guys,

I'm working on upload an image and then having it create a thumbnail of it. Its uploading the image just fine but its not running any of the code to resize it/rename it.

Any ideas? Here is my model.

Code:
<?php

class Upload_model extends CI_Model {
    
    
     function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    function do_upload() {
      
$upl = realpath(APPPATH . '../images/');      
$config['upload_path'] = $upl;
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['max_size'] = '200000';
$config['max_width'] = '728';
$config['max_height'] = '90';

$this->load->library('upload', $config);
$this->load->library('image_lib');
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$data = array('error' => $this->upload->display_errors());
}
else
{
$data1 = array('upload_data' => $this->upload->data());
$image= $data1['upload_data']['file_name'];

$configBig = array();
$configBig['image_library'] = 'gd2';
$configBig['source_image'] = $upl.$image;
$configBig['create_thumb'] = TRUE;
$configBig['maintain_ratio'] = FALSE;
$configBig['width'] = 728;
$configBig['height'] = 90;
$configBig['thumb_marker'] = "_big";
$this->image_lib->initialize($configBig);
$this->image_lib->resize();
$this->image_lib->clear();
unset($configBig);

$configBig = array();
$configBig['image_library'] = 'gd2';
$configBig['source_image'] = $upl.$image;
$configBig['create_thumb'] = TRUE;
$configBig['maintain_ratio'] = FALSE;
$configBig['width'] = 100;
$configBig['height'] = 100;
$configBig['thumb_marker'] = "_thumb";
$this->image_lib->initialize($configBig);
$this->image_lib->resize();
$this->image_lib->clear();
unset($configBig);

$filename1 = $data1['upload_data']['raw_name'].'_big'.$data1['upload_data']['file_ext'];
$filename2 = $data1['upload_data']['raw_name'].'_thumb'.$data1['upload_data']['file_ext'];


rename($upl .$filename1, $upl .$rename);
rename($upl .$filename2, $upl .$rename_thumb);
unlink($upl.$image);

}
      
        
    }
    
}
    
    ?>




Theme © iAndrew 2016 - Forum software by © MyBB