1

我正在尝试使用 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 文件中指定的路径中。

4

1 回答 1

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.
}
于 2012-07-09T10:08:22.430 回答