开发者

CODEIGNITER :: how to save 2 configs for 1 library?

开发者 https://www.devze.com 2023-01-05 20:09 出处:网络
i want to use upload library, but i want to use it in 2 separate uploads .. for example avatar and profile picture. each one of them has it\'s configs .... my applic开发者_C百科ation is v.big so it\'s

i want to use upload library, but i want to use it in 2 separate uploads .. for example avatar and profile picture. each one of them has it's configs .... my applic开发者_C百科ation is v.big so it's better to save the upload configs library in a config file. but how can i save 2 configs in the same config file and load 1 of them at a time?

Thanks


You could use a helper to return the relevant config:

// /system/application/helpers/upload_config_helper.php
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('upload_config')){
    function upload_config($conf){
        switch($conf){
            case 'avatar':
                $config['allowed_types'] = 'png|jpg';
                $config['max_size'] = '1000';
                $config['max_width']  = '1024';
                $config['max_height']  = '768';
                $config['upload_path'] = '/avatars';
                return $config;
            break;
            case 'profile_pic':
                $config['allowed_types'] = 'jpg|gif';
                $config['max_size'] = '1000';
                $config['max_width']  = '1024';
                $config['max_height']  = '768';
                $config['upload_path'] = '/profile/pics';
                return $config;
            break;
        }
    }   
}
?>

then in your controller :

$this->load->helper('upload_config_helper');
$avatar_config=upload_config('avatar');

$this->load->library('upload', $avatar_config);
$this->upload->initialize($avatar_config);
0

精彩评论

暂无评论...
验证码 换一张
取 消