Codeigniter load custom upload config

笑着哭i 提交于 2019-12-13 04:55:01

问题


I have a small problem. I have a custom configuration file for uploading. I want to load the settings without redefining them.

Okay, my configuration look like this:

config.php

$config['upload_path'] = 'tmp/';
$config['allowed_types'] = 'zip';
$config['file_name'] = '';
$config['max_size'] = '';
$config['encrypt_name'] = false;
$config['remove_spaces'] = true;

Controller

// Here is my problem $config[]
// How to load settings from config.php without again defining $config array

$config['upload_path'] =   $this->config->item('upload_path');
$config['allowed_types'] = $this->config->item('allowed_types');
$config['file_name'] =     $this->config->item('file_name');
$config['max_size'] =      $this->config->item('max_size');
$config['encrypt_name'] =  $this->config->item('encrypt_name');
$config['remove_spaces'] = $this->config->item('remove_spaces');  

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

if(!$this->upload->do_upload())
{
    $this->session->set_flashdata('error', $this->upload->display_errors());
    redirect('extension/');
}

I want to bypass the redefinition of $config['test] = $this->config->item('test');

Is this impossible?


回答1:


I am not sure if I am missing something, but simply do not put the lines in your controller. This will effectively not redeclare it?




回答2:


http://ellislab.com/codeigniter/user-guide/libraries/config.html describes how to load custom config items. I would recommend creating a custom config file as the CI website suggests and just loading that custom config file where you want.

So you'd have something like $this->config->load('custom_upload_settings', FALSE, TRUE); and in that file you'd have the settings you'd want to override.

// Loads a config file named custom_upload_settings.php and assigns it to an index named "blog_settings" $this->config->load('custom_upload_settings', TRUE);

// Retrieve a config item named site_name contained within the custom_upload_settings array $site_name = $this->config->item('site_name', 'custom_upload_settings');



来源:https://stackoverflow.com/questions/16149810/codeigniter-load-custom-upload-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!