接连三篇文章都是关于七牛云的,呵呵。感受我都帮他们作了不小推广了哈。php
首发于:https://www.skiy.net/201605094039.htmlhtml
由于七牛云的 SDK 用了命名空间等高级的不多接触到的货,因此对于咱们这种菜逼来讲。挺折腾的。
首先,由于没有为 Codeigniter 定制,因此把SDK 放到 libraries 目录还不行,还须要再写几个文件来处理。redis
制做流程:sublime-text
一、将 SDK目录php-sdk-7.0.7/src下的 Qiniu 文件夹复制粘贴到 libraries;
二、在 Qiniu 文件夹下新建文件名为Autoloader.php的文件,即 Qiniu/Autoloader.php,这一步很关键:
Autoloader.phpui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<
?
php
/**
*
* Autoloader.php
* @author : Skiychan <dev@skiy.net>
* @link : https://www.skiy.net
* @created : 5/7/16
* @modified:
* @version : 0.0.1
* @doc : https://www.skiy.net/201605094039.html
*/
namespace
Qiniu
;
class
Autoloader
{
private
$
directory
;
private
$
prefix
;
private
$
prefixLength
;
public
function
__construct
(
$
baseDirectory
=
__DIR__
)
{
$
this
->
directory
=
$
baseDirectory
;
$
this
->
prefix
=
__NAMESPACE__
.
'\\'
;
$
this
->
prefixLength
=
strlen
(
$
this
->
prefix
)
;
}
public
function
autoload
(
$
class
)
{
if
(
0
===
strpos
(
$
class
,
$
this
->
prefix
)
)
{
$
parts
=
explode
(
'\\'
,
substr
(
$
class
,
$
this
->
prefixLength
)
)
;
$
filepath
=
$
this
->
directory
.
DIRECTORY
_SEPARATOR
.
implode
(
DIRECTORY_SEPARATOR
,
$
parts
)
.
'.php'
;
if
(
is_file
(
$
filepath
)
)
{
require
$
filepath
;
}
}
}
public
static
function
register
(
)
{
spl_autoload_register
(
array
(
new
self
(
)
,
'autoload'
)
)
;
}
}
|
上面这一段代码几乎照搬了Predis的,这个流弊啊。基本能用了。this
三、在 libraries 目录下新建文件为 Qiniu.php,代码以下:spa
四、使用方式基本和官方相同,只不过由于是后加载的文件,因此没法使用 use 命名空间,因此必须输入全名(new Qiniu\Storage\BucketManager),代码以下:.net