⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

resizing more than one pic on same table



Cynthia Alderete Segalá
  • profile picture
  • Member

Posted 08 March 2016 - 18:49 PM

I think it must be easy but I can´t do it...
I have 4 images on same table:

$crud->set_field_upload('logo','../uploads');
$crud->set_field_upload('foto_divisoria','../uploads');
$crud->set_field_upload('foto_contacto','../uploads');
$crud->set_field_upload('foto_servicios','../uploads');

 


and one of this images  (logo) should be resized.. so I can´t use this line on callback in order to resize just one:
 
$file_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name;
 
Because I can´t know the upload number of the image that I have to resize . Any help?.. Thanks a lot!

 


Cynthia Alderete Segalá
  • profile picture
  • Member

Posted 08 March 2016 - 20:21 PM

Ok.. Maybe is not the better way but worked for me: (I´m just testing, forgive the dirty code)

On my function:
 

....
$crud->set_field_upload('logo','../uploads');
 
$crud->callback_after_update(array($this, 'resize_logo'));
 
 
$crud->set_field_upload('foto_divisoria','../uploads');
$crud->set_field_upload('foto_contacto','../uploads');
$crud->set_field_upload('foto_servicios','../uploads');
....
 
And then, callback function:
 
function resize_logo($post_array,$primary_key)
{
    
$this->load->library('image_moo');
 
//tring to catch path from DB
 
$this->db->select('logo');
$this->db->from('texto_web');
$this->db->where('texto_web.id',$primary_key);
 
$query = $this->db->get();
 
if ($query->num_rows() > 0)
{
  foreach ($query->result() as $row)
  {
 $path_db = $row->logo;
 
  }
}
 
 
 
    //Is only one file uploaded so it ok to use it with $uploader_response[0].
    $file_uploaded = '../uploads/'.$path_db; 
 
    $this->image_moo->load($file_uploaded)->resize(250,250)->save($file_uploaded,true);
 
    return true;
 
}