So I've been Googling this for a bit, can't seem to find an answer.
From what I understand, this code: $this->upload->initialize()
initializes the CI file upload class using the upload.php
config file. What I want to do is use a different file.
I tried $this->upload->initialize('upload_other')
, but that doesn't seem to work. I know you can just set a $config
array in the controller, but I'm trying to avoid that.
Is this possible? Am I approaching this the wrong way?
You can not Initialize / override configurations like that.
You can initialize by
$this->config->load('upload');
-- Some code Here --
$this->config->load('upload_other');
-- Some code Here --
OR you can do it by array as follows.
$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);
If you want to have anouther upload at same time you can change your config array.
$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);
UPDATE
you can specify your general data in config file. say
config['width'] = '100';
config['width2'] = '100';
Now use in your controller like
config['width'] = $this->config->item('width');
config2['width'] = $this->config->item('width2');
this way you can reuse same settings.
Why are you trying to avoid the use of a config-array? The other way is to create the upload.php-config file. If you want to use diferent configurations accross different controllers, you can always create and load a complete custom config-file: Codeigniter userguide Here you can create multiple variables with differen upload-config arrays.
You can load this config-file in every controller and use these configurations by using the initialize method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.