Multiple uploads + resizing

edited November 2011 in Modules

I've been having issues with uploading images in my model. I have this so far:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Products_model extends Base_module_model {
public $required = array('product_name','product_part_number','product_first_image');
public $image_fields=array('product_first_image_upload','product_second_image_upload',
public $thumb = array("width"=>88,"height"=>88);
public $big = array("width"=>300,"height"=>300);
public $product_path; /* IMAGES UPLOAD TO images/products/ (thumbs/) */

function __construct() {
$this->product_path = realpath(APPPATH . '../images/products');

function form_fields($values=array()) {
$fields = parent::form_fields($values);
//form stuff
return $fields;

function on_after_post($values) {
return $values

Basically, I need to make this so that when the images are sent, the model will, on_after_post, create uniformly sized small and large thumbnails (sent under the names in the var, $image_fields). I've tried everything and I would LOVE any help you could offer.



  • edited 1:43AM
    Have you looked at the projects model in the demo branch:

    It has a lot of that code to taking images and resizing them an placing them into a folder code you will probably need.
  • edited November 2011
    Thanks for getting back to me quickly! That's a great start, but I need to edit (potentially) multiple photos at the same time, am I able to do this with $data = $CI->upload->data();?

    Edit: working brilliantly for one item. Thanks!
  • edited 1:43AM
    The uploaded information is saved on the model in the $this->upload_data property which is an array of all the uploaded files information obtained from $CI->upload->data()
  • edited 1:43AM
    Okay, I'll have a play with this and see how it goes. Thanks again :).
  • edited 1:43AM
    Just getting back to you to confirm that you're a genius. Cheers! Much appreciated.
  • edited 1:43AM
    Glad you got it working!
Sign In or Register to comment.