【问题标题】:Setting a config value dynamically in the controller in Codeigniter?在 Codeigniter 的控制器中动态设置配置值?
【发布时间】:2012-07-08 17:19:59
【问题描述】:

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

【问题讨论】:

    标签: codeigniter file-upload configuration image-upload


    【解决方案1】:

    试试这个:

    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.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多