From 9288fe3dcb99474e7094e6f8e1b0e9fcee52e011 Mon Sep 17 00:00:00 2001 From: dieter Date: Thu, 19 May 2016 11:40:38 +0200 Subject: [PATCH] Fixing deprecated error when uploading file attachments in PHP 5.5+ --- src/Jira/Api/Client/CurlClient.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Jira/Api/Client/CurlClient.php b/src/Jira/Api/Client/CurlClient.php index 4668ed9..6c805f7 100644 --- a/src/Jira/Api/Client/CurlClient.php +++ b/src/Jira/Api/Client/CurlClient.php @@ -90,6 +90,7 @@ public function sendRequest( if ($method == 'POST') { curl_setopt($curl, CURLOPT_POST, 1); if ($isFile) { + $data['file'] = $this->getCurlValue($data['file']); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } else { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); @@ -122,4 +123,19 @@ public function sendRequest( return $data; } + + /** + * If necessary, replace curl file @ string with a CURLFile object (for PHP 5.5 and up) + * + * @param string $fileString The string in @-format as it is used on PHP 5.4 and older. + * @return \CURLFile|string + */ + protected function getCurlValue($fileString) + { + if (!function_exists('curl_file_create')) { + return $fileString; + } + + return curl_file_create(substr($fileString, 1)); + } }