Skip to content

Commit 3993865

Browse files
committed
using CURLFile class if PHP version >= 5.5.
1 parent 91b0a32 commit 3993865

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/JiraClient.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,29 @@ public function upload($context, $upload_file) {
189189
$ch=curl_init();
190190
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
191191
curl_setopt($ch, CURLOPT_URL, $url);
192+
193+
// send file
194+
curl_setopt($ch, CURLOPT_POST, true);
195+
196+
if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5) {
197+
$attachments = realpath($upload_file);
198+
$filename = basename($upload_file);
192199

193-
/* CURLFile support PHP 5.5
194-
$cf = new \CURLFile(realpath($upload_file), 'image/png', $upload_file);
195-
$this->log->addDebug('CURLFile=' . var_export($cf, true));
196-
*/
200+
curl_setopt($ch, CURLOPT_POSTFIELDS,
201+
array('file' => '@' . $attachments . ';filename=' . $filename));
202+
203+
$this->log->addDebug('using legacy file upload');
204+
} else {
205+
// CURLFile require PHP > 5.5
206+
$attachments = new \CURLFile(realpath($upload_file));
207+
$attachments->setPostFilename( basename($upload_file));
208+
209+
curl_setopt($ch, CURLOPT_POSTFIELDS,
210+
array('file'=>$attachments));
197211

198-
$attachments = realpath($upload_file);
199-
$filename = basename($upload_file);
212+
$this->log->addDebug('using CURLFile=' . var_export($attachments, true));
213+
}
200214

201-
// send file
202-
curl_setopt($ch, CURLOPT_POST, true);
203-
curl_setopt($ch, CURLOPT_POSTFIELDS,
204-
array('file' => '@' . $attachments . ';filename=' . $filename));
205-
206215
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
207216

208217
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST);

0 commit comments

Comments
 (0)