codeigniterfile-uploadmultiple-input

How to upload file from multiple inputs with codeigniter


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);
        }
    }

Solution

  • 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);