From 335e7a8b059a2c70777b2bba2a37e1acfc275d64 Mon Sep 17 00:00:00 2001 From: longbai Date: Fri, 23 May 2014 20:33:18 +0800 Subject: [PATCH 1/5] add 5.5 curl file --- qiniu/io.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/qiniu/io.php b/qiniu/io.php index 8f003495..c992eb56 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; } } From baf485376b5bc60bf4e20709918405d71149b1bf Mon Sep 17 00:00:00 2001 From: longbai Date: Fri, 23 May 2014 20:33:31 +0800 Subject: [PATCH 2/5] add travis 5.5 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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" From bb6ab0dd62b6c035e89665f07de5218276dc9fc2 Mon Sep 17 00:00:00 2001 From: longbai Date: Fri, 23 May 2014 20:37:32 +0800 Subject: [PATCH 3/5] tab2space --- qiniu/io.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiniu/io.php b/qiniu/io.php index c992eb56..80365e18 100644 --- a/qiniu/io.php +++ b/qiniu/io.php @@ -46,7 +46,7 @@ function Qiniu_Put($upToken, $key, $body, $putExtra) // => ($putRet, $err) function createFile($filename, $mime) { - // PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax + // 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); From a5072915287c0d4b740706d7099faa3d228f473d Mon Sep 17 00:00:00 2001 From: longbai Date: Fri, 23 May 2014 20:39:56 +0800 Subject: [PATCH 4/5] fixed char --- qiniu/io.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiniu/io.php b/qiniu/io.php index 80365e18..d953dc7c 100644 --- a/qiniu/io.php +++ b/qiniu/io.php @@ -44,7 +44,7 @@ function Qiniu_Put($upToken, $key, $body, $putExtra) // => ($putRet, $err) return Qiniu_Client_CallWithMultipartForm($client, $QINIU_UP_HOST, $fields, $files); } -function createFile($filename, $mime) +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 From 8b1ed1c50c461c766a3adea2f428d2ebe85f1a38 Mon Sep 17 00:00:00 2001 From: longbai Date: Fri, 23 May 2014 20:45:11 +0800 Subject: [PATCH 5/5] add comma --- qiniu/io.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiniu/io.php b/qiniu/io.php index d953dc7c..d77a03bf 100644 --- a/qiniu/io.php +++ b/qiniu/io.php @@ -53,7 +53,7 @@ function createFile($filename, $mime) } // Use the old style if using an older version of PHP - $value = "@{$filename}" + $value = "@{$filename}"; if (!empty($mime)) { $value .= ';type=' . $mime; }