Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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 Curl使用JIRA rest attachments api附加多个图像?_Rest_Api_Jira_Attachment - Fatal编程技术网

我们如何通过PHP Curl使用JIRA rest attachments api附加多个图像?

我们如何通过PHP Curl使用JIRA rest attachments api附加多个图像?,rest,api,jira,attachment,Rest,Api,Jira,Attachment,我可以通过Jira Rest Api附加一个图像,但当我尝试通过它发送多个图像时,它会失败。这是我的单附件代码。需要帮助才能使多个附件正常工作 参考: 下面的代码对我来说很好,希望对我有所帮助 $username = "xxxxx"; $password = "xxxxx"; $url = "https://YourUrl/rest/api/latest/issue/YourKey/attachments"; $attachments = array("attachment1", "att

我可以通过Jira Rest Api附加一个图像,但当我尝试通过它发送多个图像时,它会失败。这是我的单附件代码。需要帮助才能使多个附件正常工作

参考:


下面的代码对我来说很好,希望对我有所帮助

$username = "xxxxx";
$password = "xxxxx";

$url = "https://YourUrl/rest/api/latest/issue/YourKey/attachments";

$attachments = array("attachment1", "attachment2", "attachment3");
$curl = curl_init();
for ($i = 0; $i < count($attachments); $i++) {
$attachmentPath = "/your/attachment/path/$attachments[$i]";
$filename = array_pop(explode('/', $attachmentPath));

$cfile = new CURLFile($attachmentPath);
$cfile->setPostFilename($filename);

$data = array('file' => $cfile);

$headers = array(
    'Content-Type: multipart/form-data',
    'X-Atlassian-Token: nocheck'
);

curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($curl);
$ch_error = curl_error($curl);

if ($ch_error) {
    echo "cURL Error: $ch_error";
} else {
    echo $result;
}
}
curl_close($curl);
$username=“xxxxx”;
$password=“xxxxx”;
$url=”https://YourUrl/rest/api/latest/issue/YourKey/attachments";
$attachments=数组(“attachment1”、“attachment2”、“attachment3”);
$curl=curl_init();
对于($i=0;$isetPostFilename($filename);
$data=array('file'=>$cfile);
$headers=数组(
'内容类型:多部分/表单数据',
“X-Atlassian-Token:nocheck”
);
curl_setopt($curl,CURLOPT_USERPWD,“$username:$password”);
curl_setopt($curl,CURLOPT_URL,$URL);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl,CURLOPT_VERBOSE,1);
curl_setopt($curl,CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
$result=curl\u exec($curl);
$chu error=curl\u error($curl);
如果($CHU错误){
回显“卷曲错误:$Chu错误”;
}否则{
回声$结果;
}
}
curl_close($curl);

是否可以通过单个api调用来实现这一点@幸运的是,我现在找不到解决办法。
$username = "xxxxx";
$password = "xxxxx";

$url = "https://YourUrl/rest/api/latest/issue/YourKey/attachments";

$attachments = array("attachment1", "attachment2", "attachment3");
$curl = curl_init();
for ($i = 0; $i < count($attachments); $i++) {
$attachmentPath = "/your/attachment/path/$attachments[$i]";
$filename = array_pop(explode('/', $attachmentPath));

$cfile = new CURLFile($attachmentPath);
$cfile->setPostFilename($filename);

$data = array('file' => $cfile);

$headers = array(
    'Content-Type: multipart/form-data',
    'X-Atlassian-Token: nocheck'
);

curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($curl);
$ch_error = curl_error($curl);

if ($ch_error) {
    echo "cURL Error: $ch_error";
} else {
    echo $result;
}
}
curl_close($curl);