Codeigniter加载自定义上传配置 [英] Codeigniter load custom upload config
问题描述
我有一个小问题。我有一个自定义配置文件用于上传。
好吧,我的配置看起来像这样:
config.php
$ config ['upload_path'] ='tmp /';
$ config ['allowed_types'] ='zip';
$ config ['file_name'] ='';
$ config ['max_size'] ='';
$ config ['encrypt_name'] = false;
$ config ['remove_spaces'] = true;
控制器
//这是我的问题$ config []
//如何从config.php加载设置,而不再定义$ 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 /');
}
我想绕过$ config ['test] = $ this的重新定义 - > config-> item('test');
这不可能吗?
http://ellislab.com/codeigniter/user-guide/libraries/config.html 说明如何以加载自定义配置项。我建议创建一个自定义配置文件作为CI网站建议,只需加载自定义配置文件,你想要的。
所以你会有像 $ this-> config-> load('custom_upload_settings',FALSE,TRUE);
,并且在该文件中您将要覆盖的设置。
//加载名为custom_upload_settings.php的配置文件,并将其分配给名为blog_settings的索引
$ this-> config-> load('custom_upload_settings',TRUE);
//检索custom_upload_settings数组中包含的名为site_name的配置项
$ site_name = $ this-> config-> item('site_name','custom_upload_settings');
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?
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');
这篇关于Codeigniter加载自定义上传配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!