Skip to content

Commit a4eb86f

Browse files
committed
Merge pull request #5 from rwifeng/rs_test
rs and rsf test
2 parents e4e6f34 + d135773 commit a4eb86f

File tree

15 files changed

+573
-14
lines changed

15 files changed

+573
-14
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ php:
44
- 5.3
55
- 5.4
66
before_script:
7-
- export QINIU_ACCESS_KEY="iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV"
8-
- export QINIU_SECRET_KEY="6QTOr2Jg1gcZEWDQXKOGZh5PziC2MCV5KsntT70j"
7+
- export QINIU_ACCESS_KEY="Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ"
8+
- export QINIU_SECRET_KEY="b5b5vNg5nnkwkPfW5ayicPE_pj6hqgKMQEaWQ6JD"
9+
- export QINIU_BUCKET_NAME="phpsdk"
10+
- export QINIU_KEY_NAME="file_name"
911
script:
1012
- cd tests; phpunit .
1113

CHANGELOG.md

Whitespace-only changes.

docs/README.md

Whitespace-only changes.

qiniu/auth_digest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ public function SignWithData($data) // => $token
3131
public function SignRequest($req, $incbody) // => ($token, $error)
3232
{
3333
$url = $req->URL;
34-
$data = $url['path'];
34+
$url = parse_url($url['path']);
35+
$data = '';
36+
if (isset($url['path'])) {
37+
$data = $url['path'];
38+
}
3539
if (isset($url['query'])) {
3640
$data .= '?' . $url['query'];
3741
}
@@ -40,7 +44,6 @@ public function SignRequest($req, $incbody) // => ($token, $error)
4044
if ($incbody) {
4145
$data .= $req->Body;
4246
}
43-
4447
return $this->Sign($data);
4548
}
4649
}

qiniu/conf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$QINIU_UP_HOST = 'http://up.qbox.me';
44
$QINIU_RS_HOST = 'http://rs.qbox.me';
5-
$QINIU_RSP_HOST = 'http://rsp.qbox.me';
5+
$QINIU_RSF_HOST = 'http://rsf.qbox.me';
66

77
$QINIU_ACCESS_KEY = '<Please apply your access key>';
88
$QINIU_SECRET_KEY = '<Dont send your secret key to anyone>';

qiniu/fop.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
require_once("auth_digest.php");
4+
5+
// --------------------------------------------------------------------------------
6+
// class Qiniu_ImageView
7+
8+
class Qiniu_ImageView {
9+
public $Mode;
10+
public $Width;
11+
public $Height;
12+
public $Quality;
13+
public $Format;
14+
15+
public function MakeRequest($url)
16+
{
17+
$ops = array($this->Mode);
18+
19+
if (!empty($this->Width)) {
20+
$ops[] = 'w/' . $this->Width;
21+
}
22+
if (!empty($this->Height)) {
23+
$ops[] = 'h/' . $this->Height;
24+
}
25+
if (!empty($this->Quality)) {
26+
$ops[] = 'q/' . $this->Quality;
27+
}
28+
if (!empty($this->Format)) {
29+
$ops[] = 'format/' . $this->Format;
30+
}
31+
32+
return $url . "?imageView/" . implode('/', $ops);
33+
}
34+
}
35+
36+
// --------------------------------------------------------------------------------
37+
// class Qiniu_Exif
38+
39+
class Qiniu_Exif {
40+
41+
public function MakeRequest($url)
42+
{
43+
return $url . "?exif";
44+
}
45+
46+
}
47+
48+
// --------------------------------------------------------------------------------
49+
// class Qiniu_ImageInfo
50+
51+
class Qiniu_ImageInfo {
52+
53+
public function MakeRequest($url)
54+
{
55+
return $url . "?imageInfo";
56+
}
57+
58+
}

qiniu/http.php

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Qiniu_Error
99
{
1010
public $Err; // string
11-
public $Reqid; // string
11+
public $Reqid; // string
1212
public $Details; // []string
1313
public $Code; // int
1414

@@ -48,7 +48,7 @@ class Qiniu_Response
4848

4949
public function __construct($code, $body)
5050
{
51-
$this->StatusCode = code;
51+
$this->StatusCode = $code;
5252
$this->Header = array();
5353
$this->Body = $body;
5454
$this->ContentLength = strlen($body);
@@ -62,7 +62,7 @@ function Qiniu_Header_Get($header, $key) // => $val
6262
{
6363
$val = @$header[$key];
6464
if (isset($val)) {
65-
if (isarray($val)) {
65+
if (is_array($val)) {
6666
return $val[0];
6767
}
6868
return $val;
@@ -117,10 +117,19 @@ function Qiniu_Client_do($req) // => ($resp, $error)
117117
CURLOPT_CUSTOMREQUEST => 'POST',
118118
CURLOPT_URL => $url['path']
119119
);
120+
$httpHeader = $req->Header;
121+
if (!empty($httpHeader))
122+
{
123+
$header = array();
124+
foreach($httpHeader as $key => $parsedUrlValue) {
125+
$header[] = "$key: $parsedUrlValue";
126+
}
127+
$options[CURLOPT_HTTPHEADER] = $header;
128+
}
120129
$body = $req->Body;
121130
if (!empty($body)) {
122131
$options[CURLOPT_POSTFIELDS] = $body;
123-
$options[CURLOPT_POSTFIELDSIZE] = strlen($body);
132+
//$options[CURLOPT_POSTFIELDSIZE] = strlen($body);
124133
}
125134
curl_setopt_array($ch, $options);
126135
$result = curl_exec($ch);
@@ -161,6 +170,7 @@ public function Exec($req) // => ($resp, $error)
161170
function Qiniu_Client_ret($resp) // => ($data, $error)
162171
{
163172
$code = $resp->StatusCode;
173+
$data = null;
164174
if ($code >= 200 && $code <= 299) {
165175
if ($resp->ContentLength !== 0) {
166176
$data = json_decode($resp->Body, true);
@@ -201,5 +211,62 @@ function Qiniu_Client_CallNoRet($self, $url) // => $error
201211
return Qiniu_ResponseError($resp);
202212
}
203213

214+
function Qiniu_Client_CallWithForm($self, $url, $params, $contentType = 'application/x-www-form-urlencoded') // => ($data, $error)
215+
{
216+
$u = array('path' => $url);
217+
if ($contentType === 'application/x-www-form-urlencoded' && is_array($params)) {
218+
$params = http_build_query($params);
219+
}
220+
$req = new Qiniu_Request($u, $params);
221+
$req->Header['Content-Type'] = $contentType;
222+
list($resp, $err) = $self->Exec($req);
223+
if ($err !== null) {
224+
return array(null, $err);
225+
}
226+
return Qiniu_Client_ret($resp);
227+
}
228+
229+
function Qiniu_Client_CallWithMultiPart($self, $url, $fields, $files)
230+
{
231+
list($contentType, $body) = Qiniu_Encode_MultiPart_Form($fields, $files);
232+
return Qiniu_Client_CallWithForm($self, $url, $body, $contentType);
233+
}
234+
204235
// --------------------------------------------------------------------------------
205236

237+
function Qiniu_Encode_MultiPart_Form($fields, $files) // => ($contentType, $body)
238+
{
239+
$eol = "\r\n";
240+
$data = array();
241+
if ($fields == '') {
242+
$fields = array();
243+
}
244+
if ($files == '') {
245+
$files = array();
246+
}
247+
248+
$mimeBoundary = md5(time());
249+
foreach ($fields as $name => $val){
250+
array_push($data, '--' . $mimeBoundary);
251+
array_push($data, "Content-Disposition: form-data; name=$name");
252+
array_push($data, '');
253+
array_push($data, $val);
254+
}
255+
256+
foreach ($files as $file) {
257+
array_push($data, '--' . $mimeBoundary);
258+
list($name, $fileName, $fileCxt) = $file;
259+
array_push($data, "Content-Disposition: form-data; name=$name; filename=$fileName");
260+
array_push($data, 'Content-Type: application/octet-stream');
261+
array_push($data, '');
262+
array_push($data, $fileCxt);
263+
}
264+
265+
array_push($data, '--' . $mimeBoundary);
266+
array_push($data, '');
267+
268+
$body = implode($eol, $data);
269+
$contentType = 'multipart/form-data; boundary=' . $mimeBoundary;
270+
return array($contentType, $body);
271+
}
272+

qiniu/io.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
require_once("http.php");
4+
require_once("auth_digest.php");
5+
6+
7+
define('UNDEFINED_KEY', "?");
8+
define('NO_CRC32', 0);
9+
define('AUTO_CRC32', 1);
10+
define('WITH_CRC32', 2);
11+
12+
// ----------------------------------------------------------
13+
// class Qiniu_PutExtra
14+
15+
class Qiniu_PutExtra
16+
{
17+
public $Params;
18+
public $MimeType;
19+
public $Crc32;
20+
public $CheckCrc;
21+
}
22+
23+
function Qiniu_Put($upToken, $key, $body, $putExtra) // => ($data, $err)
24+
{
25+
global $QINIU_UP_HOST;
26+
if ($key == null) {
27+
$key = UNDEFINED_KEY;
28+
}
29+
$fields = array('key' => $key, 'token' => $upToken);
30+
31+
if ( $putExtra->CheckCrc == AUTO_CRC32 || $putExtra->CheckCrc == WITH_CRC32 ) {
32+
$fields['crc32'] = $putExtra->Crc32;
33+
}
34+
$files = array(array('file', $key, $body));
35+
36+
$client = new Qiniu_Client(null);
37+
return Qiniu_Client_CallWithMultiPart($client, $QINIU_UP_HOST, $fields, $files);
38+
}
39+
40+
function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($data, $err)
41+
{
42+
global $QINIU_UP_HOST;
43+
if ($key == null) {
44+
$key = UNDEFINED_KEY;
45+
}
46+
$fields = array('key' => $key, 'token' => $upToken, 'file' => '@' . $localFile);
47+
48+
if ( $putExtra->CheckCrc == AUTO_CRC32 ) {
49+
$hash = hash_file('crc32b', $localFile);
50+
$crc32 = unpack('N', pack('H*', $hash));
51+
$fields['crc32'] = $crc32[1];
52+
} elseif ($putExtra->CheckCrc == WITH_CRC32 ) {
53+
$fields['crc32'] = $putExtra->Crc32;
54+
}
55+
56+
$client = new Qiniu_Client(null);
57+
return Qiniu_Client_CallWithForm($client, $QINIU_UP_HOST, $fields, 'multipart/form-data');
58+
}

0 commit comments

Comments
 (0)