Welcome Guest, Not a member yet? Register   Sign In
uploading multiple files to different folders
#2

[eluser]xwero[/eluser]
Code:
$this->load->library('upload'); // no config values

$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';
        
$keys = array_keys($_FILES);
$errors = array();
$uploads = array();

foreach($keys as $field){
        
        if($field == 'somefield')
        {
           $config['upload_path'] = './uploads2/';
        }
        else
        {
           $config['upload_path'] = './uploads/';
        }        

        $this->upload->initialize($config) // the config values are bound here to the library

        if ( ! $this->upload->do_upload($field))
        {
            $errors[] = $this->upload->display_errors();
        }    
        else
        {
            $uploads[] = $this->upload->data(); // previous code oversight
        }
}
If you have several fields that need to upload to different paths you better use a switch instead of an if else structure.


Messages In This Thread
uploading multiple files to different folders - by El Forum - 11-29-2007, 03:35 AM
uploading multiple files to different folders - by El Forum - 11-29-2007, 03:48 AM
uploading multiple files to different folders - by El Forum - 11-29-2007, 03:53 AM
uploading multiple files to different folders - by El Forum - 11-29-2007, 04:02 AM
uploading multiple files to different folders - by El Forum - 11-29-2007, 04:18 AM
uploading multiple files to different folders - by El Forum - 11-29-2007, 04:38 AM
uploading multiple files to different folders - by El Forum - 11-29-2007, 02:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB