Skip to content

Commit 47578ec

Browse files
committed
CDN_Qiniu.uploadFile added
1 parent a704d83 commit 47578ec

File tree

7 files changed

+64
-3
lines changed

7 files changed

+64
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
*.swp
1616

1717
.DS_Store
18+
19+
*.zip

Auth/Auth/Api/Auth/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Class Api_Auth_Group 组接口服务类
4+
* Auth扩展 - 组接口服务类
55
* @author: hms 2015-6-8
66
*/
77
class Api_Auth_Group extends PhalApi_Api

Auth/Auth/Api/Auth/Rule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Class Api_Auth_Rule 规则接口服务类
4+
* Auth扩展 - 规则接口服务类
55
* @author: hms 2015-6-8
66
*/
77
class Api_Auth_Rule extends PhalApi_Api
@@ -145,4 +145,4 @@ public function del()
145145
$rs['code'] = $r;
146146
return $rs;
147147
}
148-
}
148+
}

Qiniu/CDN/Api/Qiniu/CDN.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* 七牛扩展 - CDN云端接口
4+
*
5+
* @author: dogstar 2015-03-17
6+
*/
7+
8+
class Api_Qiniu_CDN extends PhalApi_Api
9+
{
10+
const CODE_MISS_UPLOAD_FILE = 1;
11+
const CODE_FAIL_TO_UPLOAD_FILE = 2;
12+
const CODE_FAIL_TO_UPDATE = 3;
13+
14+
/**
15+
* 上传文件到七牛CDN
16+
* @desc 只支持单个文件上传,需要使用字段file上传文件
17+
* @return int code 上传状态码,0上传成功,1缺少文件,2上传失败
18+
* @return string url 成功上传后返回文件链接
19+
* @return string msg 提供信息
20+
*/
21+
public function uploadFile()
22+
{
23+
$rs = array('code' => self::CODE_FAIL_TO_UPLOAD_FILE, 'url' => '', 'msg' => T('fail to upload file'));
24+
25+
if (!isset($_FILES['file'])) {
26+
$rs['code'] = self::CODE_MISS_UPLOAD_FILE;
27+
$rs['msg'] = T('miss upload file');
28+
return $rs;
29+
}
30+
31+
if ($_FILES["file"]["error"] > 0) {
32+
$rs['code'] = self::CODE_FAIL_TO_UPLOAD_FILE;
33+
$rs['msg'] = T('failed to upload file with error: {error}', array('error' => $_FILES['file']['error']));
34+
DI()->logger->debug('failed to upload file with error: ' . $_FILES['file']['error']);
35+
return $rs;
36+
}
37+
38+
$url = DI()->qiniu->uploadFile($_FILES['file']['tmp_name']);
39+
if (!empty($url)) {
40+
$rs['code'] = 0;
41+
$rs['url'] = $url;
42+
$rs['msg'] = '';
43+
}
44+
@unlink($_FILES['file']['tmp_name']);
45+
46+
return $rs;
47+
}
48+
}

Qiniu/Lite.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public function __construct($config = NULL) {
2727
if ($this->config === NULL) {
2828
$this->config = DI()->config->get('app.Qiniu');
2929
}
30+
31+
DI()->loader->addDirs('./Library/Qiniu/CDN');
3032
}
3133

3234
/**

User/User/Api/User/User/Info.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
/**
3+
* User扩展-用户信息服务
4+
* @author dogstar 20170312
5+
*/
6+
27
class Api_User_User_Info extends PhalApi_Api {
38

49
public function getRules()

User/User/Api/User/User/Login.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
/**
3+
* User扩展 - 登录服务
4+
* @author dogstar 20170312
5+
*/
26

37
class Api_User_User_Login extends PhalApi_Api {
48

0 commit comments

Comments
 (0)