I’m trying to upload a file using the REST API with PHP. I created a simple web form to upload a file, and when submit it I get “RT/4.4.4 200 Ok # Correspondence added”, and the ticket is uploaded with the corresponded text, but the attachment isn’t in the ticket.
Below is the code I’m using.
<?php $url = "http://".$url ."/REST/1.0/ticket/".$ticket_num ."/comment?user=$username&pass=$password"; $attachment_1 = curl_file_create($_FILES["file"]["tmp_name"], $_FILES["file"]["type"], $_FILES["file"]["name"]); $fields = [ "content" => "id: ".$ticket_num ."\nAction: correspond\nText: test attachment\nAttachment:" .$_FILES["file"]["name"], "attachment_1" => $attachment_1 ]; $fields_string = http_build_query($fields); $ch = curl_init(); $fp = fopen($_FILES["file"]["tmp_name"], 'r'); curl_setopt($ch, CURLOPT_USERPWD, $username .":".$password); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($_FILES["file"]["tmp_name"])); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'CURL_callback'); curl_setopt($ch, CURLOPT_BUFFERSIZE, 128); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); $post_result = curl_exec($ch); echo $post_result; ?>