是否可以在配置文件/文件夹中写入上传图像配置代码?

时间:2014-06-24 06:19:03

标签: codeigniter-2

我想将此代码放在配置文件/文件夹中。

                  $config['upload_path'] = './upload/';
                  $config['allowed_types'] = 'jpeg|jpg|png';
                  $config['max_size']     = '1000';
                  $config['max_width']  = '1024';
                  $config['max_height']  = '768';

2 个答案:

答案 0 :(得分:0)

为什么不呢?

              $config['upload']['upload_path'] = './upload/';
              $config['upload']['allowed_types'] = 'jpeg|jpg|png';
              $config['upload']['max_size']     = '1000';
              $config['upload']['max_width']  = '1024';
              $config['upload']['max_height']  = '768';

并在某处使用它你需要它像这样

$this->load->library('upload', $this->config->item('upload'));

答案 1 :(得分:0)

乔治的答案会起作用,但有一种正式的方法可以做到:

  

只需创建一个名为upload.php的新文件,在该文件中添加$ config数组。然后将文件保存在:config / upload.php中,它将自动使用。如果您将首选项保存在配置文件中,则无需使用$ this-> upload->初始化函数。

按照上面提到的方法,您不需要使用任何配置加载上传库,它会自动加载它们。

检查Codeigniter user guide以获取更多信息。