Skip to content

Instantly share code, notes, and snippets.

@adorr
Created September 20, 2013 20:24
Show Gist options
  • Save adorr/6643339 to your computer and use it in GitHub Desktop.
Save adorr/6643339 to your computer and use it in GitHub Desktop.
<?php
$fields = array(
'file_name' => "wallpaper.jpg",
'content-type' => "image/jpg",
'content' => '"'.base64_encode(file_get_contents("./wallpaper.jpg")).'"'
);
$fields_string = json_encode($fields);
echo $fields_string;
echo "\n\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://yoursite.desk.com/api/v2/cases/1/attachments");
curl_setopt($ch, CURLOPT_PORT, 443);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_USERPWD, "email:password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($fields_string)
)
);
$return = curl_exec($ch);
echo $return;
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment