Skip to content

Commit cdc8416

Browse files
author
Alexander Obuhovich
committed
Merge pull request #86 from DerMika/curldeprecated
Fixing deprecated error when uploading file attachments in PHP 5.5+
2 parents 7b7adf3 + 9288fe3 commit cdc8416

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Jira/Api/Client/CurlClient.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function sendRequest(
9090
if ($method == 'POST') {
9191
curl_setopt($curl, CURLOPT_POST, 1);
9292
if ($isFile) {
93+
$data['file'] = $this->getCurlValue($data['file']);
9394
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
9495
} else {
9596
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
@@ -122,4 +123,19 @@ public function sendRequest(
122123

123124
return $data;
124125
}
126+
127+
/**
128+
* If necessary, replace curl file @ string with a CURLFile object (for PHP 5.5 and up)
129+
*
130+
* @param string $fileString The string in @-format as it is used on PHP 5.4 and older.
131+
* @return \CURLFile|string
132+
*/
133+
protected function getCurlValue($fileString)
134+
{
135+
if (!function_exists('curl_file_create')) {
136+
return $fileString;
137+
}
138+
139+
return curl_file_create(substr($fileString, 1));
140+
}
125141
}

0 commit comments

Comments
 (0)