CI3接入阿里云OSS库类V2.2.4
OSS-SDK升级到2.0之后变动还是挺大的,今天正好新项目要用到,所以决定弃用了老项目的SDK(V1.1.5),使用目前最新的SDK(V2.2.4)废话不多说,直接放代码
\application\config\config.php
<?php
$config['oss']['accessKeyId'] = '';
$config['oss']['accessKeySecret'] = '';
$config['oss']['endpoint'] = 'oss-cn-hangzhou.aliyuncs.com';
\application\libraries\CI_OSS.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH.'libraries/OSS/autoload.php';
use OSS\OssClient;
use OSS\Core\OssException;
class CI_OSS {
private $_CI;
private $_oss;
public function __construct() {
$this->_CI =& get_instance();
$this->_CI->load->config('oss');
$config = $this->_CI->config->item('oss');
if(empty($this->_oss)) {
$this->_oss = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint']);
}
return $this->_oss;
}
/**
* @name 使用魔术方法捕获所有未注册方法
*/
public function __call($method, $arg_array) {
return call_user_func_array(array($this->_oss, $method), $arg_array);
}
}
\application\controllers\Oss.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Oss extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function demo() {
$this->load->library('CI_OSS');
$data = $this->ci_oss->listBuckets();
var_dump($data);die;
}
}
SDK可以直接从官网下载最新版
大赞!!!
页:
[1]