Hello All,
I posted a similar question regarding how to post a single file using the Confluence REST API with php curl. I was able to get that to work with this code:
$ch = curl_init();
$postFile = __DIR__ . '\afile.txt';
$cFile = curl_file_create($postFile);
$postData = array('file' => $cFile);
$headers = array();
$headers[] = "X-Atlassian-Token: no-check";
curl_setopt($ch, CURLOPT_URL, "http://localhost:8090/rest/api/content/31391749/child/attachment");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1);
curl_setopt($ch, CURLOPT_USERPWD, "username" . ":" . "password");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_exec($ch);
curl_close($ch);
Now I'm trying to post multiple files at once and have been unsuccessful in my attempts thus far, This is my most recent attempt:
$ch = curl_init();
$postFiles = array(__DIR__ . '\afile.txt', __DIR__ . '\bfile.txt',);
$postData = array();
foreach($postFiles as $index => $postFile) {
$cFile = curl_file_create($postFile);
$postData[$index] = $cFile;
}
$postData = array('file' => $cFile);
$headers = array();
$headers[] = "X-Atlassian-Token: no-check";
curl_setopt($ch, CURLOPT_URL, "http://localhost:8090/rest/api/content/31391749/child/attachment");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1);
curl_setopt($ch, CURLOPT_USERPWD, "username" . ":" . "password");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_exec($ch);
curl_close($ch);
The code above only posts the bfile.txt file as an attachment.
I've been able to post multiple files using cURL, but I need to do it using php curl. Any ideas or suggestions on how to amend the code above to enable the posting of multiple files? Thanks in advance!
*NOTE: this post was somehow duplicated. I tried to find a way to delete one, but it seems that's not possible at the moment.*
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.