Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 5.5 #79

Merged
merged 5 commits into from
May 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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