Skip to content

Commit

Permalink
Merge pull request #80 from qiniu/develop
Browse files Browse the repository at this point in the history
Release 6.1.10
  • Loading branch information
longbai committed May 30, 2014
2 parents 45afca3 + 3048719 commit 4c2327a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 40 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ php:
- 5.2
- 5.3
- 5.4
- 5.5
before_script:
- export QINIU_ACCESS_KEY="Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ"
- export QINIU_SECRET_KEY="b5b5vNg5nnkwkPfW5ayicPE_pj6hqgKMQEaWQ6JD"
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"php": ">=5.2.4"
},
"autoload": {
"psr-0": { "qiniu\\": "qiniu" }
}
"files": ["qiniu/rs_utils.php"]
}
}
2 changes: 0 additions & 2 deletions docs/README.gist.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ SDK源码地址:<https://github.com/qiniu/php-sdk/tags>
public $DetectMime; // 可选。如果设为非0值,则忽略上传端传递的文件MimeType信息,使用七牛服务器侦测内容后的判断结果。
public $FsizeLimit; // 可选。int类型,超过限制大小的上传内容会被判为上传失败,返回413状态码。
public $SaveKey; // 可选。自定义资源名格式。
public $Transform; // 可选。指定资源经过怎样的处理后再保存。
public $FopTimeout; // 可选。int类型,指定transform的超时时间,如果文件处理超过此值,则认为上传失败。
public $MimeLimit; // 可选。限定上传的文件类型。
}

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

Expand Down
27 changes: 20 additions & 7 deletions qiniu/io.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Qiniu_Put($upToken, $key, $body, $putExtra) // => ($putRet, $err)
}
if ($putExtra->Params) {
foreach ($putExtra->Params as $k=>$v) {
$fields[$k] = $v;
$fields[$k] = $v;
}
}

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

function createFile($filename, $mime)
{
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
// See: https://wiki.php.net/rfc/curl-file-upload
if (function_exists('curl_file_create')) {
return curl_file_create($filename, $mime);
}

// Use the old style if using an older version of PHP
$value = "@{$filename}";
if (!empty($mime)) {
$value .= ';type=' . $mime;
}

return $value;
}

function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($putRet, $err)
{
global $QINIU_UP_HOST;
Expand All @@ -52,11 +69,7 @@ function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($putRet, $e
$putExtra = new Qiniu_PutExtra;
}

if (!empty($putExtra->MimeType)) {
$localFile .= ';type=' . $putExtra->MimeType;
}

$fields = array('token' => $upToken, 'file' => '@' . $localFile);
$fields = array('token' => $upToken, 'file' => createFile($localFile, $putExtra->MimeType));
if ($key === null) {
$fname = '?';
} else {
Expand All @@ -73,7 +86,7 @@ function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($putRet, $e
}
if ($putExtra->Params) {
foreach ($putExtra->Params as $k=>$v) {
$fields[$k] = $v;
$fields[$k] = $v;
}
}

Expand Down
6 changes: 1 addition & 5 deletions qiniu/rs.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function MakeRequest($baseUrl, $mac) // => $privateUrl

function Qiniu_RS_MakeBaseUrl($domain, $key) // => $baseUrl
{
$keyEsc = rawurlencode($key);
$keyEsc = str_replace("%2F", "/", rawurlencode($key));
return "http://$domain/$keyEsc";
}

Expand All @@ -55,7 +55,6 @@ class Qiniu_RS_PutPolicy
public $SaveKey;
public $PersistentOps;
public $PersistentNotifyUrl;
public $Transform;
public $FopTimeout;
public $MimeLimit;

Expand Down Expand Up @@ -109,9 +108,6 @@ public function Token($mac) // => $token
if (!empty($this->PersistentNotifyUrl)) {
$policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl;
}
if (!empty($this->Transform)) {
$policy['transform'] = $this->Transform;
}
if (!empty($this->FopTimeout)) {
$policy['fopTimeout'] = $this->FopTimeout;
}
Expand Down
23 changes: 1 addition & 22 deletions tests/IoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ public function testPut_mimetype() {
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
}

public function testPut_exclusive()
{
public function testPut_exclusive() {
$key = 'testPut_exclusive' . getTid();
$scope = $this->bucket . ':' . $key;
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
Expand All @@ -157,27 +156,7 @@ public function testPut_exclusive()
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}
public function testPut_transform() {
$key = 'testPut_transform' . getTid();
$scope = $this->bucket . ':' . $key;
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);

$putPolicy = new Qiniu_RS_PutPolicy($scope);
$putPolicy->Transform = "imageMogr2/format/png";
$putPolicy->ReturnBody = '{"key": $(key), "hash": $(etag), "mimeType":$(mimeType)}';
$upToken = $putPolicy->Token(null);

list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, null);
$this->assertNull($ret);
$this->assertEquals($err->Err, "fop fail or timeout");
var_dump($err);

$pic_path = "../docs/gist/logo.jpg";
list($ret, $err) = Qiniu_PutFile($upToken, $key, $pic_path, null);
$this->assertNull($err);
$this->assertEquals($ret["mimeType"], "image/png");
var_dump($ret);
}
public function testPut_mimeLimit() {
$key = 'testPut_mimeLimit' . getTid();
$scope = $this->bucket . ':' . $key;
Expand Down
6 changes: 6 additions & 0 deletions tests/RsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,11 @@ public function testBatchDeleteMoveCopy()

Qiniu_RS_BatchDelete($this->client, array($e2, $e3, $e4));
}

public function testUrlEncode() {
$url = Qiniu_RS_MakeBaseUrl("www.qiniu.com", "a/b/c d");
var_dump($url);
$this->assertEquals($url, "http://www.qiniu.com/a/b/c%20d");
}
}

0 comments on commit 4c2327a

Please sign in to comment.