Skip to content

Commit

Permalink
Merge pull request #79 from longbai/add_5.5_rm_5.2
Browse files Browse the repository at this point in the history
Add 5.5
  • Loading branch information
longbai committed May 23, 2014
2 parents 1b2abe2 + 8b1ed1c commit 3048719
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 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
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

0 comments on commit 3048719

Please sign in to comment.