Welcome Guest, Not a member yet? Register   Sign In
image resizing in a single page not working
#1

[eluser]mahfuj[/eluser]
Hi

I have been trying to resize both image and thumbnail in a same program block; but only the first resize works, the second one does not.

Can anyone help, please?



Code:
function file_upload($title,$upload_path,$allowed_types,$max_size,$max_width,
$max_height,$width,$height,$thumb_marker)
{
$config['upload_path'] = $upload_path;
$config['allowed_types'] = $allowed_types;
$config['max_size'] = $max_size;
$config['remove_spaces'] = TRUE;
$config['overwrite'] = TRUE;
$config['max_width']  = $max_width;
$config['max_height']  = $max_height;
$this->load->library('upload', $config);
if(!$this->upload->do_upload($title))
{
  $this->upload->display_errors();
  exit();
}
else
{
  $data = array('upload_data' => $this->upload->data());
  $this->resize($data['upload_data']['full_path'],
                                    $data['upload_data']['file_name'],$width,$height,$thumb_marker);
                $ext = strrchr($data['upload_data']['file_name'], '.');
  $name = ($ext === FALSE) ? $data['upload_data']['file_name'] :
                                                           substr($data['upload_data']['file_name'], 0, -strlen($ext));
  $name = $name.$thumb_marker;
  $data['upload_data']['file_name'] = $name.$ext;
    
  return $data;
}

}
  
function resize($path,$file,$width,$height,$thumb_marker)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $path;
$config['dynamic_output'] = FALSE;
$config['create_thumb'] = TRUE;
$config['thumb_marker']= $thumb_marker;
        $config['maintain_ratio']=TRUE;
$config['width']= $width;
$config['height']= $height;
$config['new_image'] = './images/'.$file;
$this->load->library('image_lib',$config);
$this->image_lib->resize();
}
  
function updateProduct()
{
$data = array('name' => db_clean($_POST['name']),'shortdesc' => db_clean($_POST['shortdesc']),
        'longdesc' => db_clean($_POST['longdesc'],5000),
'prod_status' => db_clean($_POST['status'],8),
'category_id' => id_clean($_POST['category_id']),'featured' => db_clean($_POST['featured'],5));
  
         if ($_FILES)
{
  if (strlen($_FILES['thumbnail']['name']))
  {
   $thumbnail=$this->file_upload('thumbnail','./images/','gif|jpg|png','1024','1024','768','80','50','_thumb');
    
   if ($thumbnail['upload_data']['file_name'])
   {
    $data['thumbnail'] = base_url().'images/'.$thumbnail['upload_data']['file_name'];
   }
  }
  if (strlen($_FILES['image']['name']))
  {
   $image=$this->file_upload('image','./images/','gif|jpg|png','1024','1024','768','320','200','_image');
   if ($image['upload_data']['file_name'])
   {
    $data['image'] = base_url().'images/'.$image['upload_data']['file_name'];
   }
  }


}
  
$this-> db-> where('id', id_clean($_POST['id']));
$this->db->update('tbl_products', $data);
}

Mahfuj
#2

[eluser]mahfuj[/eluser]
Here I have found the solution
http://ellislab.com/forums/viewthread/195548/




Theme © iAndrew 2016 - Forum software by © MyBB