|
OSS-SDK升级到2.0之后变动还是挺大的,今天正好新项目要用到,所以决定弃用了老项目的SDK(V1.1.5),使用目前最新的SDK(V2.2.4)
废话不多说,直接放代码
\application\config\config.php
PHP复制代码
<?php
$config['oss']['accessKeyId'] = '';
$config['oss']['accessKeySecret'] = '';
$config['oss']['endpoint'] = 'oss-cn-hangzhou.aliyuncs.com';
复制代码
\application\libraries\CI_OSS.php
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复制代码
<?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可以直接从官网下载最新版
|
评分
-
查看全部评分
|