diff --git a/.travis.yml b/.travis.yml index 399de88c..415177f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/composer.json b/composer.json index 3ee4d3fc..8e8aa9f7 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,6 @@ "php": ">=5.2.4" }, "autoload": { - "psr-0": { "qiniu\\": "qiniu" } - } + "files": ["qiniu/rs_utils.php"] + } } diff --git a/docs/README.gist.md b/docs/README.gist.md index 5a2b15c7..dc582fac 100644 --- a/docs/README.gist.md +++ b/docs/README.gist.md @@ -316,8 +316,6 @@ SDK源码地址: public $DetectMime; // 可选。如果设为非0值,则忽略上传端传递的文件MimeType信息,使用七牛服务器侦测内容后的判断结果。 public $FsizeLimit; // 可选。int类型,超过限制大小的上传内容会被判为上传失败,返回413状态码。 public $SaveKey; // 可选。自定义资源名格式。 - public $Transform; // 可选。指定资源经过怎样的处理后再保存。 - public $FopTimeout; // 可选。int类型,指定transform的超时时间,如果文件处理超过此值,则认为上传失败。 public $MimeLimit; // 可选。限定上传的文件类型。 } diff --git a/docs/README.md b/docs/README.md index e8292767..1a1c8217 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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; // 可选。限定上传的文件类型。 } diff --git a/qiniu/io.php b/qiniu/io.php index 8f003495..d77a03bf 100644 --- a/qiniu/io.php +++ b/qiniu/io.php @@ -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; } } @@ -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; @@ -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 { @@ -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; } } diff --git a/qiniu/rs.php b/qiniu/rs.php index 1166b5d8..425ba8f3 100644 --- a/qiniu/rs.php +++ b/qiniu/rs.php @@ -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"; } @@ -55,7 +55,6 @@ class Qiniu_RS_PutPolicy public $SaveKey; public $PersistentOps; public $PersistentNotifyUrl; - public $Transform; public $FopTimeout; public $MimeLimit; @@ -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; } diff --git a/tests/IoTest.php b/tests/IoTest.php index 746f1aca..089b65de 100644 --- a/tests/IoTest.php +++ b/tests/IoTest.php @@ -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); @@ -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; diff --git a/tests/RsTest.php b/tests/RsTest.php index 2368198c..b02375a2 100644 --- a/tests/RsTest.php +++ b/tests/RsTest.php @@ -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"); + } }