Skip to content

Commit

Permalink
Merge pull request #59 from qiniu/develop
Browse files Browse the repository at this point in the history
Release v6.1.5
  • Loading branch information
xushiwei committed Feb 13, 2014
2 parents dbf237f + 4732c3b commit 43c656c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## CHANGE LOG

### v6.1.5

2014-2-13 issues [#59](https://github.com/qiniu/php-sdk/pull/59)

- 修复 PutExtra.MimeType 无效的问题


### v6.1.4

2013-10-25 issues [#52](https://github.com/qiniu/php-sdk/pull/52)
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: PHP SDK
---

# PHP SDK 使用指南

此 SDK 适用于 PHP 5.1.0 及其以上版本。基于 [七牛云存储官方API](http://docs.qiniu.com) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。

Expand Down
5 changes: 3 additions & 2 deletions qiniu/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,11 @@ function Qiniu_Build_MultipartForm($fields, $files) // => ($contentType, $body)

foreach ($files as $file) {
array_push($data, '--' . $mimeBoundary);
list($name, $fileName, $fileBody) = $file;
list($name, $fileName, $fileBody, $mimeType) = $file;
$mimeType = empty($mimeType) ? 'application/octet-stream' : $mimeType;
$fileName = Qiniu_escapeQuotes($fileName);
array_push($data, "Content-Disposition: form-data; name=\"$name\"; filename=\"$fileName\"");
array_push($data, 'Content-Type: application/octet-stream');
array_push($data, "Content-Type: $mimeType");
array_push($data, '');
array_push($data, $fileBody);
}
Expand Down
6 changes: 5 additions & 1 deletion qiniu/io.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Qiniu_Put($upToken, $key, $body, $putExtra) // => ($putRet, $err)
$fields['crc32'] = $putExtra->Crc32;
}

$files = array(array('file', $fname, $body));
$files = array(array('file', $fname, $body, $putExtra->MimeType));

$client = new Qiniu_HttpClient;
return Qiniu_Client_CallWithMultipartForm($client, $QINIU_UP_HOST, $fields, $files);
Expand All @@ -47,6 +47,10 @@ 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);
if ($key === null) {
$fname = '?';
Expand Down
7 changes: 7 additions & 0 deletions qiniu/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ function Qiniu_Encode($str) // URLSafeBase64Encode
return str_replace($find, $replace, base64_encode($str));
}


function Qiniu_Decode($str)
{
$find = array('-', '_');
$replace = array('+', '/');
return base64_decode(str_replace($find, $replace, $str));
}
27 changes: 26 additions & 1 deletion tests/IoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,38 @@ public function testPut_mime_save()

list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
$this->assertNull($err);
$this->assertEquals($ret['mimeType'], 'application/x-httpd-php');
$this->assertEquals($ret['mimeType'], 'application/x-php');
var_dump($ret);

$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}

public function testPut_mimetype() {
$key = 'testPut_mimetype' . getTid();
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$scope = $this->bucket . ":" . $key;

$putPolicy = new Qiniu_RS_PutPolicy($scope);
$putPolicy->ReturnBody = '{"key":$(key),"mimeType":$(mimeType)}';
$upToken = $putPolicy->Token(null);

$putExtra = new Qiniu_PutExtra();
$putExtra->MimeType = 'image/jpg';

list($ret1, $err1) = Qiniu_PutFile($upToken, $key, __file__, $putExtra);
var_dump($ret1);
$this->assertNull($err1);
$this->assertEquals($ret1['mimeType'], 'image/jpg');

list($ret2, $err2) = Qiniu_Put($upToken, $key, "hello world", $putExtra);
var_dump($ret2);
$this->assertNull($err2);
$this->assertEquals($ret2['mimeType'], 'image/jpg');

$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
}

public function testPut_exclusive()
{
$key = 'testPut_exclusive' . getTid();
Expand Down

0 comments on commit 43c656c

Please sign in to comment.