Skip to content

Commit 3048719

Browse files
committed
Merge pull request #79 from longbai/add_5.5_rm_5.2
Add 5.5
2 parents 1b2abe2 + 8b1ed1c commit 3048719

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
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"

qiniu/io.php

Lines changed: 20 additions & 7 deletions
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

0 commit comments

Comments
 (0)