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

[eluser]Benjamin Bowles[/eluser]
I'm having some trouble get a file upload code working.

I've got a controller that calls a function from a library that I've created, this happens each time I want an image uploaded, you can see this in the snippet of code from the controller that is calling the function:

Code:
if(isset($_POST['addProof'])) {
  $aupload = $this->proofing->uploadImage('./assets/artwork/', 'jpg', 'artwork');
  $iupload = $this->proofing->uploadImage('./assets/invoice/', 'pdf', 'invoice');
  $this->proofs_model->add($aupload, $iupload);
  redirect('/proof');
}

The code for the uploadImage() function is below:

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', $config);
  
  if($CI->upload->do_upload($file)) {
   $d = $CI->upload->data();
   $filename = $d['file_name'];
   return $filename;
  } else {                
   return '';                        
  }
}

The call to the uploadImage() function seems to work the first time (for the artwork upload), but for the second upload (invoice) it seems to fail.

Is there some sort of upload->clear() that I should do each time?

Any help would be truly appreciated!


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