Skip to content

Commit 4c2327a

Browse files
committed
Merge pull request #80 from qiniu/develop
Release 6.1.10
2 parents 45afca3 + 3048719 commit 4c2327a

File tree

8 files changed

+31
-40
lines changed

8 files changed

+31
-40
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ php:
33
- 5.2
44
- 5.3
55
- 5.4
6+
- 5.5
67
before_script:
78
- export QINIU_ACCESS_KEY="Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ"
89
- export QINIU_SECRET_KEY="b5b5vNg5nnkwkPfW5ayicPE_pj6hqgKMQEaWQ6JD"

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"php": ">=5.2.4"
1010
},
1111
"autoload": {
12-
"psr-0": { "qiniu\\": "qiniu" }
13-
}
12+
"files": ["qiniu/rs_utils.php"]
13+
}
1414
}

docs/README.gist.md

-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ SDK源码地址:<https://github.com/qiniu/php-sdk/tags>
316316
public $DetectMime; // 可选。如果设为非0值,则忽略上传端传递的文件MimeType信息,使用七牛服务器侦测内容后的判断结果。
317317
public $FsizeLimit; // 可选。int类型,超过限制大小的上传内容会被判为上传失败,返回413状态码。
318318
public $SaveKey; // 可选。自定义资源名格式。
319-
public $Transform; // 可选。指定资源经过怎样的处理后再保存。
320-
public $FopTimeout; // 可选。int类型,指定transform的超时时间,如果文件处理超过此值,则认为上传失败。
321319
public $MimeLimit; // 可选。限定上传的文件类型。
322320
}
323321

docs/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@ if ($err !== null) {
409409
public $DetectMime; // 可选。如果设为非0值,则忽略上传端传递的文件MimeType信息,使用七牛服务器侦测内容后的判断结果。
410410
public $FsizeLimit; // 可选。int类型,超过限制大小的上传内容会被判为上传失败,返回413状态码。
411411
public $SaveKey; // 可选。自定义资源名格式。
412-
public $Transform; // 可选。指定资源经过怎样的处理后再保存。
413-
public $FopTimeout; // 可选。int类型,指定transform的超时时间,如果文件处理超过此值,则认为上传失败。
414412
public $MimeLimit; // 可选。限定上传的文件类型。
415413
}
416414

qiniu/io.php

+20-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Qiniu_Put($upToken, $key, $body, $putExtra) // => ($putRet, $err)
3434
}
3535
if ($putExtra->Params) {
3636
foreach ($putExtra->Params as $k=>$v) {
37-
$fields[$k] = $v;
37+
$fields[$k] = $v;
3838
}
3939
}
4040

@@ -44,6 +44,23 @@ function Qiniu_Put($upToken, $key, $body, $putExtra) // => ($putRet, $err)
4444
return Qiniu_Client_CallWithMultipartForm($client, $QINIU_UP_HOST, $fields, $files);
4545
}
4646

47+
function createFile($filename, $mime)
48+
{
49+
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
50+
// See: https://wiki.php.net/rfc/curl-file-upload
51+
if (function_exists('curl_file_create')) {
52+
return curl_file_create($filename, $mime);
53+
}
54+
55+
// Use the old style if using an older version of PHP
56+
$value = "@{$filename}";
57+
if (!empty($mime)) {
58+
$value .= ';type=' . $mime;
59+
}
60+
61+
return $value;
62+
}
63+
4764
function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($putRet, $err)
4865
{
4966
global $QINIU_UP_HOST;
@@ -52,11 +69,7 @@ function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($putRet, $e
5269
$putExtra = new Qiniu_PutExtra;
5370
}
5471

55-
if (!empty($putExtra->MimeType)) {
56-
$localFile .= ';type=' . $putExtra->MimeType;
57-
}
58-
59-
$fields = array('token' => $upToken, 'file' => '@' . $localFile);
72+
$fields = array('token' => $upToken, 'file' => createFile($localFile, $putExtra->MimeType));
6073
if ($key === null) {
6174
$fname = '?';
6275
} else {
@@ -73,7 +86,7 @@ function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($putRet, $e
7386
}
7487
if ($putExtra->Params) {
7588
foreach ($putExtra->Params as $k=>$v) {
76-
$fields[$k] = $v;
89+
$fields[$k] = $v;
7790
}
7891
}
7992

qiniu/rs.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function MakeRequest($baseUrl, $mac) // => $privateUrl
3232

3333
function Qiniu_RS_MakeBaseUrl($domain, $key) // => $baseUrl
3434
{
35-
$keyEsc = rawurlencode($key);
35+
$keyEsc = str_replace("%2F", "/", rawurlencode($key));
3636
return "http://$domain/$keyEsc";
3737
}
3838

@@ -55,7 +55,6 @@ class Qiniu_RS_PutPolicy
5555
public $SaveKey;
5656
public $PersistentOps;
5757
public $PersistentNotifyUrl;
58-
public $Transform;
5958
public $FopTimeout;
6059
public $MimeLimit;
6160

@@ -109,9 +108,6 @@ public function Token($mac) // => $token
109108
if (!empty($this->PersistentNotifyUrl)) {
110109
$policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl;
111110
}
112-
if (!empty($this->Transform)) {
113-
$policy['transform'] = $this->Transform;
114-
}
115111
if (!empty($this->FopTimeout)) {
116112
$policy['fopTimeout'] = $this->FopTimeout;
117113
}

tests/IoTest.php

+1-22
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public function testPut_mimetype() {
132132
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
133133
}
134134

135-
public function testPut_exclusive()
136-
{
135+
public function testPut_exclusive() {
137136
$key = 'testPut_exclusive' . getTid();
138137
$scope = $this->bucket . ':' . $key;
139138
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
@@ -157,27 +156,7 @@ public function testPut_exclusive()
157156
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
158157
$this->assertNull($err);
159158
}
160-
public function testPut_transform() {
161-
$key = 'testPut_transform' . getTid();
162-
$scope = $this->bucket . ':' . $key;
163-
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
164159

165-
$putPolicy = new Qiniu_RS_PutPolicy($scope);
166-
$putPolicy->Transform = "imageMogr2/format/png";
167-
$putPolicy->ReturnBody = '{"key": $(key), "hash": $(etag), "mimeType":$(mimeType)}';
168-
$upToken = $putPolicy->Token(null);
169-
170-
list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, null);
171-
$this->assertNull($ret);
172-
$this->assertEquals($err->Err, "fop fail or timeout");
173-
var_dump($err);
174-
175-
$pic_path = "../docs/gist/logo.jpg";
176-
list($ret, $err) = Qiniu_PutFile($upToken, $key, $pic_path, null);
177-
$this->assertNull($err);
178-
$this->assertEquals($ret["mimeType"], "image/png");
179-
var_dump($ret);
180-
}
181160
public function testPut_mimeLimit() {
182161
$key = 'testPut_mimeLimit' . getTid();
183162
$scope = $this->bucket . ':' . $key;

tests/RsTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,11 @@ public function testBatchDeleteMoveCopy()
8888

8989
Qiniu_RS_BatchDelete($this->client, array($e2, $e3, $e4));
9090
}
91+
92+
public function testUrlEncode() {
93+
$url = Qiniu_RS_MakeBaseUrl("www.qiniu.com", "a/b/c d");
94+
var_dump($url);
95+
$this->assertEquals($url, "http://www.qiniu.com/a/b/c%20d");
96+
}
9197
}
9298

0 commit comments

Comments
 (0)