Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向Jira'添加附件;s api_Php_Drupal_Drupal 6_Jira_Jira Rest Api - Fatal编程技术网

Php 向Jira'添加附件;s api

Php 向Jira'添加附件;s api,php,drupal,drupal-6,jira,jira-rest-api,Php,Drupal,Drupal 6,Jira,Jira Rest Api,我正在尝试使用他们的API将一个文件附加到Jira案例。我是在Drupal6(PHPV5.0)中完成这项工作的。以下是我的代码: $ch = curl_init(); $header = array( 'Content-Type: multipart/form-data', 'X-Atlassian-Token: no-check' ); $attachmentPath = $this->get_file_uploads(); //$attachmentPath comes ou

我正在尝试使用他们的API将一个文件附加到Jira案例。我是在Drupal6(PHPV5.0)中完成这项工作的。以下是我的代码:

$ch = curl_init();
$header = array(
  'Content-Type: multipart/form-data',
   'X-Atlassian-Token: no-check'
);
$attachmentPath = $this->get_file_uploads();
//$attachmentPath comes out to be something like:
//http://localhost/mySite/web/system/files/my_folder/DSC_0344_3.JPG

$data = array('file'=>"@". $attachmentPath, 'filename'=>'test.png');
$url= 'https://mysite.atlassian.net/rest/api/2/issue/20612/attachments/';

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->get_jira_headers());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,  CURLOPT_POSTFIELDS ,$data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");

$result = curl_exec($ch);
$ch_error = curl_error($ch);
问题是$result显示为false,$chu错误表示无法打开该文件。这个错误是与Drupal有关还是与我如何向Jira发送请求有关?顺便说一句,如果我使用绝对路径,比如:

$attachmentPath = 'C:\wamp\www\mySite\web\sites\mySite.net\files\my_folder\DSC_0333.JPG';

上传工作正常。

这应该适合您:

$data = array('file'=>"@". $attachmentPath . ';filename=test.png');

这是一个错误,谢谢。实际上,我无意中在这个问题上加上了悬赏,同时也打算在我加的另一个问题上加上悬赏。但是,交易就是交易,我很高兴它能起作用@杰森,不客气!是的,我想这就是让它发挥作用的主要目标!它返回卷曲错误:格式不正确
$cfile = new CURLFile($attachmentPath);
$cfile->setPostFilename('test.png');
$data = array('file'=>$cfile);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->get_jira_headers());
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);