0

我有三个不同的输入文件,我想从不同的文件夹上传它。我下面的代码在上传过程中工作正常,但它只转到始终位于“org_chart”文件夹中的单个文件夹。

这是来自我的控制器:

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

2 回答 2

1

您可以使用如下配置:

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);
}
于 2019-02-11T11:32:06.807 回答
0

经过长时间处理这个问题后,我找到了解决我问题的解决方案。Codeigniter 不允许使用新参数调用该类两次,而是必须“重新初始化”上传类。这是一些似乎与问题相同的文章。相关文章

$config['allowed_types'] = 'pdf';    
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->do_upload($key);
于 2019-02-12T02:31:18.300 回答