From 3993865b413cf700d586732314bb695b9b496c24 Mon Sep 17 00:00:00 2001 From: KwangSeob Jeong Date: Tue, 10 Mar 2015 11:36:57 +0900 Subject: [PATCH] using CURLFile class if PHP version >= 5.5. --- src/JiraClient.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/JiraClient.php b/src/JiraClient.php index 79c98392..8cf9b1e4 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -189,20 +189,29 @@ public function upload($context, $upload_file) { $ch=curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); + + // send file + curl_setopt($ch, CURLOPT_POST, true); + + if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5) { + $attachments = realpath($upload_file); + $filename = basename($upload_file); - /* CURLFile support PHP 5.5 - $cf = new \CURLFile(realpath($upload_file), 'image/png', $upload_file); - $this->log->addDebug('CURLFile=' . var_export($cf, true)); - */ + curl_setopt($ch, CURLOPT_POSTFIELDS, + array('file' => '@' . $attachments . ';filename=' . $filename)); + + $this->log->addDebug('using legacy file upload'); + } else { + // CURLFile require PHP > 5.5 + $attachments = new \CURLFile(realpath($upload_file)); + $attachments->setPostFilename( basename($upload_file)); + + curl_setopt($ch, CURLOPT_POSTFIELDS, + array('file'=>$attachments)); - $attachments = realpath($upload_file); - $filename = basename($upload_file); + $this->log->addDebug('using CURLFile=' . var_export($attachments, true)); + } - // send file - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, - array('file' => '@' . $attachments . ';filename=' . $filename)); - curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password"); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST);