I've got this form to upload a file. I want it to be uploaded as a comment in Pivotal Tracker with the API. What will I write in the code? I'm new to Curl.
Edit: In Pivotal Tracker you can upload file .jpg, .xls, etc in the comments, and it creates an downloadable icon/thumbnail.
Comments Doc: https://www.pivotaltracker.com/help/api/rest/v5#projects_project_id_stories_story_id_comments_post
File attachment Doc: https://www.pivotaltracker.com/help/api/rest/v5#file_attachment_resource
upload.html:
<form action="pt.php" method="post" enctype="multipart/form-data">
<fieldset>
<input type="file" name="pt_xls" />
<input type="submit" name="upload" value="Upload" />
</fieldset>
</form>
pt.php:
$response = pivotalTracker("https://www.pivotaltracker.com/services/v5/projects/XXXXXXXX/stories/XXXXXXXX/comments");
$resArr = array();
$resArr = json_decode($response);
echo "<pre>"; print_r($resArr); echo "</pre>";
function pivotalTracker($url) {
$pivotalAPIToken = 'XXXXXXXXXX';
$curlHeader = array("X-TrackerToken: ".$pivotalAPIToken, "Content-type: application/json");
$options = array(
CURLOPT_HTTPHEADER => $curlHeader,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => json_encode($data),
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}