Skip to content

Commit

Permalink
using CURLFile class if PHP version >= 5.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Mar 10, 2015
1 parent 91b0a32 commit 3993865
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/JiraClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3993865

Please sign in to comment.