我正在尝试使用Codegniter的上传库上传图像,图像应该上传到模型创建并返回的目录,每次更改上传目录,这是我应该的代码用于更改配置上传数组:
if ($_FILES['image']['size']!=0) {
$path = $this->homeModel->createDirectories($id);
$this->config->load('upload');
$this->config->set_item('upload', array('upload_path' => $path));
// I've also used
// $this->config->set_item('upload_path', $path);
if (!$this->upload->do_upload('image'))
echo $this->upload->display_errors();
else {
$image = $this->upload->data();
$data['image'] = $image['file_name'];
}
}
但它似乎不起作用。 upload_path没有改变,图像仍然在我在config / upload.php文件中指定的路径上传。
答案 0 :(得分:3)
试试这个:
if ($_FILES['image']['size']!=0) {
$path = $this->homeModel->createDirectories($id);
$this->config->load('upload', TRUE);
$config = $this->config->item('upload');
$config['upload_path'] = $path;
$this->upload->initialize($config);
//etc.
}