Welcome Guest, Not a member yet? Register   Sign In
Array to string conversion
#6

[eluser]Colin Williams[/eluser]
This is completely untested but I think it will work. A good starting point nonetheless

Code:
class MY_Upload extends CI_Upload {
  
   function MY_Upload()
   {
      parent::CI_Upload();
   }

   function do_multi_upload($field = 'userfile')
   {
      $success = FALSE;
      if (is_array($_FILES[$field]['error']))
      {
         // Create a pseudo file field for each file in our array
         for ($i = 0; $i < count($_FILES[$field]['error']); $i++)
         {
            // Give it a name not likely to already exist!
            $pseudo_field_name = '_psuedo_'. $field .'_'. $i;
            // Mimick the file
            $_FILES[$pseudo_field_name] = array(
               'name' => $_FILES[$field]['name'][$i],
               'size' => $_FILES[$field]['size'][$i],
               'type' => $_FILES[$field]['type'][$i],
               'tmp_name' => $_FILES[$field]['tmp_name'][$i],
               'error' => $_FILES[$field]['error'][$i]
            );
            // Let do_upload work its magic on our pseudo file field
            if (!$this->do_upload($pseudo_field_name))
            {
               $success = FALSE;
               break;
            }
            else
            {
               $success = TRUE;
            }
         }
      }
      else
      // Works just like do_upload since it's not an array of files
      {
         $success = $this->do_upload($field);
      }
      return $success;
   }
}

What I'm doing here is making copies of files from the array of files, then passing these copies onto the existing do_upload() method to process them. It's better than overriding the beast that is do_upload(), and it's probably a bit future-proof/less-hackish to not override a core library method.


Messages In This Thread
Array to string conversion - by El Forum - 07-14-2008, 10:10 AM
Array to string conversion - by El Forum - 07-14-2008, 10:44 AM
Array to string conversion - by El Forum - 07-14-2008, 10:46 AM
Array to string conversion - by El Forum - 07-14-2008, 11:27 AM
Array to string conversion - by El Forum - 07-14-2008, 11:29 AM
Array to string conversion - by El Forum - 07-14-2008, 12:04 PM
Array to string conversion - by El Forum - 07-14-2008, 03:52 PM
Array to string conversion - by El Forum - 07-14-2008, 09:48 PM
Array to string conversion - by El Forum - 07-14-2008, 10:49 PM
Array to string conversion - by El Forum - 07-14-2008, 11:15 PM
Array to string conversion - by El Forum - 07-15-2008, 01:36 AM
Array to string conversion - by El Forum - 07-15-2008, 02:51 AM
Array to string conversion - by El Forum - 07-15-2008, 03:24 AM
Array to string conversion - by El Forum - 07-15-2008, 03:38 AM
Array to string conversion - by El Forum - 07-15-2008, 05:37 AM
Array to string conversion - by El Forum - 07-17-2008, 11:55 AM
Array to string conversion - by El Forum - 07-17-2008, 12:57 PM
Array to string conversion - by El Forum - 07-17-2008, 01:04 PM
Array to string conversion - by El Forum - 07-17-2008, 02:49 PM
Array to string conversion - by El Forum - 07-18-2008, 05:32 AM
Array to string conversion - by El Forum - 07-18-2008, 06:42 AM
Array to string conversion - by El Forum - 07-18-2008, 07:22 AM
Array to string conversion - by El Forum - 08-02-2008, 01:42 PM
Array to string conversion - by El Forum - 09-28-2008, 04:12 AM
Array to string conversion - by El Forum - 02-07-2009, 04:25 PM
Array to string conversion - by El Forum - 04-14-2010, 03:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB