0

I have three different input files and I want to upload it from different folders. My codes below works fine during upload but it only goes to single folder which is always in "org_chart" folder.

This is from my Controller:

    foreach ($_FILES as $key => $value) {
        if ($key == "updated-org-chart") {
            $config['allowed_types'] = 'pdf';
        $config['upload_path']   = './assets/manpower_requisition/org_chart/';
        $this->load->library('upload', $config);
        $this->upload->do_upload($key);
        }elseif ($key == "job-description") {
            $config['allowed_types'] = 'pdf';
        $config['upload_path']   = './assets/manpower_requisition/jd/';
        $this->load->library('upload', $config);
        $this->upload->do_upload($key);
        }elseif ($key == "bsc") {
            $config['allowed_types'] = 'pdf';
        $config['upload_path']   = './assets/manpower_requisition/bsc/';
        $this->load->library('upload', $config);
        $this->upload->do_upload($key);
        }
    }

2 Answers2

1

You could using config like below :

foreach ($_FILES as $key => $value) {
    switch ($key) {
        case 'updated-org-chart':
            $config['upload_path']   = './assets/manpower_requisition/org_chart/';
            break;

        case 'job-description':
            $config['upload_path']   = './assets/manpower_requisition/jd/';
            break;

        case 'bsc':
            $config['upload_path']   = './assets/manpower_requisition/bsc/';
            break;

        default:
            $config['upload_path']   = './assets/manpower_requisition/org_chart/';
            break;
    }
    $config['allowed_types'] = 'pdf';
    $this->load->library('upload', $config);
    $this->upload->do_upload($key);
}
Hasta Dhana
  • 4,699
  • 7
  • 17
  • 26
1

After long hours on spending this problem, I've found a solution that solve my problem. Codeigniter does not allow to call the class twice with new parameter instead it has to "re-initialize" the upload class. Here are some article that seems to be the same with the problem. Related Articles

$config['allowed_types'] = 'pdf';    
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->do_upload($key);