我想使用上传库,但我想在2个单独的上传中使用它...例如头像和个人资料图片。他们每个人都有它的配置....我的应用程序是v.big所以最好将上传配置库保存在配置文件中。但是我如何在同一配置文件中保存2个配置并一次加载其中1个?
谢谢
答案 0 :(得分:1)
您可以使用帮助程序返回相关配置:
// /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;
}
}
}
?>
然后在你的控制器中:
$this->load->helper('upload_config_helper');
$avatar_config=upload_config('avatar');
$this->load->library('upload', $avatar_config);
$this->upload->initialize($avatar_config);