Welcome Guest, Not a member yet? Register   Sign In
Merge local and config file settings before initilization ?
#1

[eluser]skunkbad[/eluser]
I'm trying to create multiple configuration options in a config file:

Code:
$config['image_configuration'] = array(
    'upload_dir' => 'uploads',
    'acceptable_files' => 'gif|jpg|jpeg|png',
    'max_kb' => '200',
    'max_width' => '1024',
    'max_height' => '768'
);

$config['file_configuration'] = array(
    'upload_dir' => 'uploads',
    'acceptable_files' => 'doc|pdf',
    'max_kb' => '200',
);

In the controller, I'm trying to merge these settings with settings that only apply to the current need:

Code:
// Configure Upload class
$local_config['upload_path'] = './' . $upload_dir . '/' . $primary_dir . '/' . $secondary_dir . '/';
$config = array_merge( $local_config, $this->config->item('image_configuration') );
$this->load->library('upload', $config);

This is not working. What is the proper way to do this?
#2

[eluser]InsiteFX[/eluser]
skunkbad, you can give this a try, seems to work for me but see if it will work for you.
Code:
$data = array();


$config['image_configuration'] = array(
    'upload_dir' => 'uploads',
    'acceptable_files' => 'gif|jpg|jpeg|png',
    'max_kb' => '200',
    'max_width' => '1024',
    'max_height' => '768'
);

$config['file_configuration'] = array(
    'upload_dir' => 'uploads',
    'acceptable_files' => 'doc|pdf',
    'max_kb' => '200',
);

$upload_dir    = 'test1';
$primary_dir   = 'test2';
$secondary_dir = 'test3';

// Configure Upload class
$local_config['upload_path'] = './' . $upload_dir . '/' . $primary_dir . '/' . $secondary_dir . '/';

$data = $config['image_configuration'];

$config = array_merge($local_config, $data);

print_r($config);

InsiteFX
#3

[eluser]skunkbad[/eluser]
Ya know what, I was being stupid. My problem wasn't the merging of the config options, but that I had the wrong names of config option keys. Thanks for your time.
#4

[eluser]InsiteFX[/eluser]
Your very welcome.

InsiteFX
#5

[eluser]kikz4life[/eluser]
sorry to intrude. What do you mean by config file? Is it like the form_validation config file in application/config?. If so what would be the appropriate filename for this?
#6

[eluser]InsiteFX[/eluser]
If it is for the form_validation then it would be named form_validation

InsiteFX
#7

[eluser]Wondering Coder[/eluser]
i think what kikz4life is asking is what would the filename be? I too would like to know this. Will it be file_upload.php or upload.php?
#8

[eluser]InsiteFX[/eluser]
Sorry, yes it would be upload.php with a $config[] array.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB