所以我一直在谷歌搜索一下,似乎无法找到答案.
据我所知,这段代码:$this->upload->initialize()使用upload.php配置文件初始化CI文件上传类.我想要做的是使用不同的文件.
我试过了$this->upload->initialize('upload_other'),但这似乎不起作用.我知道你可以$config在控制器中设置一个数组,但我试图避免这种情况.
这可能吗?我是以错误的方式接近这个吗?
您无法初始化/覆盖此类配置.
你可以初始化
$this->config->load('upload');
-- Some code Here --
$this->config->load('upload_other');
-- Some code Here --
Run Code Online (Sandbox Code Playgroud)
或者您可以通过数组执行以下操作.
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);
Run Code Online (Sandbox Code Playgroud)
如果您想同时进行一次上传,可以更改配置数组.
$config2['upload_path'] = './uploads/small/';
$config2['allowed_types'] = 'gif|jpg|png';
$config2['max_size'] = '100';
$config2['max_width'] = '100';
$config2['max_height'] = '100';
$this->load->library('upload', $config2);
// Alternately you can set
$this->upload->initialize($config2);
Run Code Online (Sandbox Code Playgroud)
UPDATE
您可以在配置文件中指定常规数据.说
config['width'] = '100';
config['width2'] = '100';
Run Code Online (Sandbox Code Playgroud)
现在在你的控制器中使用
config['width'] = $this->config->item('width');
config2['width'] = $this->config->item('width2');
Run Code Online (Sandbox Code Playgroud)
这样您就可以重复使用相同的设置.