Welcome Guest, Not a member yet? Register   Sign In
Image Uploads
#6

[eluser]Benjamin Bowles[/eluser]
[quote author="Evil Wizard" date="1246907677"]I'm not sure how the loader really works but If I had coded it I wouldn't instantiate the object every time it was loaded, I'd check to see if it was already loaded and return that instance. If that is the case, then only the first instantiation of the object, and its config would be return on the second run.
try this instead:
Code:
function uploadImage($path = '', $types = '', $file = '') {
  $CI =& get_instance();
  $config['upload_path'] = $path;
  $config['allowed_types'] = $types;
  $config['encrypt_name'] = TRUE;
  $CI->load->library('upload');
  $CI->upload->initialize($config);
  
  if($CI->upload->do_upload($file)) {
   $d = $CI->upload->data();
   $filename = $d['file_name'];
   return $filename;
  } else {                
   return '';                        
  }
}
by sending the config data to the initialize method the config details are effectively reset and ready for the second upload.[/quote]

Fantastic - worked a treat. Job Done.

Thanks Evil Wizard, not so evil are you!


Messages In This Thread
Image Uploads - by El Forum - 07-06-2009, 07:45 AM
Image Uploads - by El Forum - 07-06-2009, 07:59 AM
Image Uploads - by El Forum - 07-06-2009, 08:05 AM
Image Uploads - by El Forum - 07-06-2009, 08:09 AM
Image Uploads - by El Forum - 07-06-2009, 08:14 AM
Image Uploads - by El Forum - 07-06-2009, 08:18 AM
Image Uploads - by El Forum - 07-06-2009, 08:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB