diff --git a/.travis.yml b/.travis.yml index 399de88c..415177f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/qiniu/io.php b/qiniu/io.php index 8f003495..d77a03bf 100644 --- a/qiniu/io.php +++ b/qiniu/io.php @@ -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; } } @@ -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; @@ -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 { @@ -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; } }