Skip to content

Commit 76bc05f

Browse files
committed
Merge branch 'develop'
2 parents 7cc3ced + 49b13af commit 76bc05f

File tree

7 files changed

+87
-20
lines changed

7 files changed

+87
-20
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
又拍云存储PHP SDK,基于 [又拍云存储HTTP REST API接口](http://wiki.upyun.com/index.php?title=HTTP_REST_API%E6%8E%A5%E5%8F%A3) 开发。
44

5+
## 更新说明
6+
使用1.0.x系列版本SDK的用户,注意原有部分方法已经不再推荐使用,但是处于兼容考虑目前任然保留,建议更新升级程序使用新版SDK提供的方法。
7+
58
## 使用说明
69

710
### 初始化UpYun

examples.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/get_list.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
require_once('../upyun.class.php');
3+
4+
$upyun = new UpYun('bucket', 'user', 'pwd');
5+
6+
try {
7+
echo "=========获取目录文件列表\r\n";
8+
$list = $upyun->getList('/demo/');
9+
var_dump($list);
10+
echo "=========DONE\r\n\r\n";
11+
}
12+
catch(Exception $e) {
13+
$e->getCode();
14+
$e->getMessage();
15+
}

examples/sample.jpeg

141 KB
Loading

examples/write_file.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
require_once('../upyun.class.php');
3+
4+
$upyun = new UpYun('bucket', 'user', 'pwd');
5+
6+
try {
7+
echo "=========直接上传文件\r\n";
8+
$fh = fopen('sample.jpeg', 'rb');
9+
$rsp = $upyun->writeFile('/demo/sample_normal.jpeg', $fh, True); // 上传图片,自动创建目录
10+
fclose($fh);
11+
var_dump($rsp);
12+
echo "=========DONE\n\r\n";
13+
14+
echo "=========设置MD5校验文件完整性\r\n";
15+
$opts = array(
16+
UpYun::CONTENT_MD5 => md5(file_get_contents("sample.jpeg"))
17+
);
18+
$fh = fopen('sample.jpeg', 'rb');
19+
$rsp = $upyun->writeFile('/demo/sample_md5.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
20+
fclose($fh);
21+
var_dump($rsp);
22+
echo "=========DONE\r\n\r\n";
23+
24+
echo "=========直接生成缩略图,不保存原图片,仅对图片文件有效\r\n";
25+
$opts = array(
26+
UpYun::X_GMKERL_TYPE => 'square', // 缩略图类型
27+
UpYun::X_GMKERL_VALUE => 150, // 缩略图大小
28+
UpYun::X_GMKERL_QUALITY => 95, // 缩略图压缩质量
29+
UpYun::X_GMKERL_UNSHARP => True // 是否进行锐化处理
30+
);
31+
$fh = fopen('sample.jpeg', 'rb');
32+
$rsp = $upyun->writeFile('/demo/sample_thumb_1.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
33+
fclose($fh);
34+
var_dump($rsp);
35+
echo "=========DONE\r\n\r\n";
36+
37+
echo "=========按照预先设置的缩略图类型生成缩略图类型生成缩略图,不保存原图,仅对图片空间有效\r\n";
38+
$opts = array(
39+
UpYun::X_GMKERL_THUMBNAIL => 'thumbtype'
40+
);
41+
$fh = fopen('sample.jpeg', 'rb');
42+
$rsp = $upyun->writeFile('/demo/sample_thumb_2.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
43+
fclose($fh);
44+
var_dump($rsp);
45+
echo "=========DONE\r\n\r\n";
46+
}
47+
catch(Exception $e) {
48+
$e->getCode();
49+
$e->getMessage();
50+
}

sample.jpeg

141 KB
Loading

upyun.class.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class UpYun {
7171
*/
7272
private $_file_secret = NULL;
7373

74+
/**
75+
* @deprecated
76+
*/
77+
private $_file_infos= NULL;
78+
7479
protected $endpoint;
7580

7681
/**
@@ -144,7 +149,9 @@ public function writeFile($path, $file, $auto_mkdir = False, $opts = NULL) {/*{{
144149

145150
if ($auto_mkdir === True) $opts['Mkdir'] = 'true';
146151

147-
return $this->_do_request('PUT', $path, $opts, $file);
152+
$this->_file_infos = $this->_do_request('PUT', $path, $opts, $file);
153+
154+
return $this->_file_infos;
148155
}/*}}}*/
149156

150157
/**
@@ -302,7 +309,6 @@ protected function _do_request($method, $path, $headers = NULL, $body= NULL, $fi
302309
$body = '';
303310
list($header_string, $body) = explode("\r\n\r\n", $response, 2);
304311

305-
var_dump($response);
306312
//var_dump($header_string, $body);
307313
//var_dump($http_code);
308314
if ($http_code == 200) {
@@ -470,4 +476,15 @@ public function setContentMD5($str){/*{{{*/
470476
public function setFileSecret($str){/*{{{*/
471477
$this->_file_secret = $str;
472478
}/*}}}*/
479+
480+
/**
481+
* @deprecated
482+
* 获取上传文件后的信息(仅图片空间有返回数据)
483+
* @param $key 信息字段名(x-upyun-width、x-upyun-height、x-upyun-frames、x-upyun-file-type)
484+
* return value or NULL
485+
*/
486+
public function getWritedFileInfo($key){/*{{{*/
487+
if(!isset($this->_file_infos))return NULL;
488+
return $this->_file_infos[$key];
489+
}/*}}}*/
473490
}

0 commit comments

Comments
 (0)