CodeIgniter文件上传类-初始化不同的配置文件 [英] CodeIgniter File Upload Class - Initialize different config file

查看:58
本文介绍了CodeIgniter文件上传类-初始化不同的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经在谷歌上搜索了一下,似乎找不到答案。

So I've been Googling this for a bit, can't seem to find an answer.

据我了解,这段代码: $ this-> upload-> initialize()使用 upload.php 配置文件初始化CI文件上传类。我想做的是使用其他文件。

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.

我尝试了 $ this-> upload-> initialize('upload_other'),但这没有。似乎行得通。我知道您可以在控制器中设置一个 $ config 数组,但是我正试图避免这种情况。

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.

您可以通过

$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.

这篇关于CodeIgniter文件上传类-初始化不同的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆