我有三个不同的输入文件,我想从不同的文件夹上载它。我的以下代码在上传过程中工作正常,但仅转到单个文件夹,该文件夹始终位于“ 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);
}
}
答案 0 :(得分: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);
}
答案 1 :(得分:0)
花了很长时间解决这个问题之后,我找到了解决我的问题的解决方案。 Codeigniter不允许使用新参数两次调用该类,而是必须“重新初始化”上载类。这里有些文章似乎与此问题相同。 Related Articles
$config['allowed_types'] = 'pdf';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->do_upload($key);