[eluser]n0xie[/eluser]
This implies that you upload the images at the same time you are creating the entry. Is this correct?
If so you could do something like that:
Code:
# pseudo code
class Entries extends CI_Controller
function create()
{
// all your form validation crap here
// if they pass:
$images = $this->_handle_upload();
// do damage control here if something went wrong with the file upload
if ( ! $images) show_404('something went wrong during upload');
$data = array_merge($data, $images);
$this->entries_model->save($data);
}
function _handle_upload()
{
// put all your upload code here (basically c/p your create() function)
// inside your foreach loop
// instead of inserting we do:
$fieldname = 'img' . $i;
$fieldname_small = 'img' . $i . 'sml';
$image[$fieldname] = $imagename;
$image[$fieldname_small] = str_replace('_tn','_tn2', $imagename);
$i++;
// end foreach loop
return ($error) ? FALSE : $image;
}
Obviously you could move the upload stuff to a different library/module/model instead of doing it in the controller.