First of all - i will like to say sorry to Peter - he waited for this solution for quite sometime but it was unfortunate for me and situation that i couldnt help with 1st my health then with my laptops health.
Okies- This 1 was an enhanced version of Victors - multi upload solution. It was a great solution in itself but GOD guided me to a better one where i have had a requirement for a multi multiple upload in a single form and have had a need to achieve it with GC. I am so much in love with GC - it was too tough for me to even think of leaving out GC just to achieve such small solution.
so there it was ...i am attaching the solution. Following is the structure of the same
application
|->config
|->cache.php
|->controllers
|->artists.php ----This is the sample controller giving you the example of how to use the component
|->uploaders
|->artists_photo_uploader.php ---- A sample uploader configuration to be used in the application with controller
|->gigs_photo_uploader.php ---- A sample uploader configuration to be used in the application with controller
|->uploader.php --- This is the base uploader functionality extracted and generalized on ground of solution provided by Victor
|->libraries
|->cache.php ---- This is required piece of code cuz for me session storage failed.
Now here is the explaination to all the stuff thats there
As described above .. the uploder.php is the base extracted functionality for any uploaders that needs to be for achieving the multi uploader functionality. The only difference between the multiple uploaders is a certain set of values that are extracted as configuration values. You can find the same into the sample uploader configuration files shared in the application. But a base information about the configuration that u might need to play around with .. are here
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once('uploader.php'); //include the base uploader class class Artists_photo_uploader extends Uploader { //extend the same. This is necessary for achiving the multi multiupload functionality. protected $path_to_uploade_function = 'uploaders/artists_photo_uploader/multi_uploade'; // path to function call. private $files = array(); //Required to just declare for managing the files that gets uploaded protected $default_css_path = 'assets/styles/'; //Path to the CSS protected $default_javascript_path = 'assets/scripts/'; //Path where the scripts will be stored / found protected $path_to_directory = 'assets/artists/'; //Path where the files will get uploaded // table description protected $file_table = 'artist_pictures'; //Name of the table where the files will get stored protected $category_id_field = 'artist_id'; //ID of the master table relation (foreign key) protected $file_name_field = 'picture'; //Name of the field that stores the filename protected $primary_key = 'id'; //Primary key protected $allowed_types = 'gif|jpeg|jpg|png'; //Defination of the file types allowed - necessary requirement for u to control the type of content you set for uploading the files. function __construct() { parent::__construct(); } }
The above configuration are clear to explain itself. Please dont ask me to explain how the base uploader class works - it is just the extract of Victors code.
Now in the controller...
public function index() { try{ $crud = new Grocery_crud(); $crud->set_table('artists'); $crud->set_subject('Artist'); $crud->fields('title', 'description', 'pictures'); require_once FCPATH . "application/controllers/uploaders/artists_photo_uploader.php"; /* set the uploader needed to manage the upload. Now here we can set many uploaders as we need. * i have currently just set 1 uploader only ... u can have many together ... thats the beauty of this extension */ //Set the multi uploader functionality $artistsPhotoUploader = new Artists_photo_uploader(); //we need to have the object for the same. //Nsex 2 lines are necvessary for gneerating the multi upload code $crud->callback_add_field('pictures', array($artistsPhotoUploader, 'add_upload_fied')); $crud->callback_edit_field('pictures', array($artistsPhotoUploader, 'edit_upload_fied')); //This callbacks are also necessary to be declared. Without it .. the application will faily in its totality. //Both the callbacks are just to be declared as described below. $crud->callback_before_insert(array($this, '_set_files')); $crud->callback_after_insert(array($this, '_save_files_into_db')); $crud->callback_before_update(array($this, '_set_files')); $crud->callback_after_update(array($this, '_save_files_into_db')); $artistsPhotoUploader->set_js($crud); //Set the js callbacks and stuff for individual uploader. //In case u have had a video uploader also with this - u would have had to call the set_js for that object too.... for ex // $artistVideoUploader->set_js($crud); $output = $crud->render(); $this->load->view('crud.php',$output); }catch(Exception $e){ show_error($e->getMessage().' --- '.$e->getTraceAsString()); } } function _set_files($post_array) { require_once FCPATH . "application/controllers/uploaders/artists_photo_uploader.php"; $photo_uploader = new Artists_photo_uploader(); $photo_uploader->_set_files($post_array); //as described above - in case of multi-multi uploader u will need to have the same declaraion for other uploaders too... for ex. /******* * require_once FCPATH . "application/controllers/uploaders/artists_video_uploader.php"; * $video_uploader = new Artists_video_uploader(); * $video_uploader->_set_files($post_array); */ //What this functionality dose is - it will grab all the files that are uploaded by the user - store the values for the same into a cached file. Yes - here for me the session storage failed .. hence i had to take cache in use. Thats why u see a cache.php library above in the code. then it just removes the values and the upload field defined. } function _save_files_into_db($post_array, $primary_key) { require_once FCPATH . "application/controllers/uploaders/artists_photo_uploader.php"; $photo_uploader = new Artists_photo_uploader(); $photo_uploader->_save_files_into_db($post_array, $primary_key); //Here - u need to follow the same steps as shared in the function above. This will store the uploaded objects into its respective tables. }
PHEW ----- thats a lot of explaination that went in and hope it makes the picture whole lot more clear to all of you guys out there.. so happy (multi) - multiuploading.
and off course - Happy GCing :)