[eluser]PHP Programmer[/eluser]
i am trying to upload multiple files to multiple folders. For this I am using this code:
function do_upload()
{
$files = array('userfile1'=>array('upload_path'=>'./uploads/file1/','allowed_types'=>'gif|jpg|png','max_size'=>100), 'userfile2'=>array('upload_path'=>'./uploads/file2/','allowed_types'=>'gif|jpg|png','max_size'=>100));
$this->load->library('upload');
//Below Line Added By ANUJ
foreach($files as $field=>$settings)
{
$this->upload->initialize($settings);
//Above Line Added By ANUJ
if ( ! $this->upload->do_upload($field))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
echo $data['upload_data']['file_name'];
}
}
}
// Multi Files
function do_upload()
{
$config['upload_path'] = './uploads/file1/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$this->load->library('upload');
foreach($_FILES as $key => $value)
{
if( ! empty($key))
{
$this->upload->initialize($config);
if ( ! $this->upload->do_upload($key))
{
print_r($errors[] = $this->upload->display_errors());
}
else
{
//$this->Process_image->process_pic();
}
}
}
}
In 1st code, it comes an error "Unable to find a post variable called userfile." How to resolve it?
The 2nd code runs fine separately but not when merge with 1st code.
Please suggest how to overcome this problem?
TIA