Skip to content

Instantly share code, notes, and snippets.

@tim-peterson
Last active November 28, 2019 12:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tim-peterson/4962406 to your computer and use it in GitHub Desktop.
Save tim-peterson/4962406 to your computer and use it in GitHub Desktop.
Docverter PHP-CURL example
//set POST variables
$url = 'http://c.docverter.com/convert';
$fields = array('from' => 'markdown',
'to' => 'pdf',
'input_files[]' => "@/".realpath('markdown.md').";type=text/x-markdown; charset=UTF-8"
);
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
//write to file
$fp = fopen('uploads/result.pdf', 'w');
fwrite($fp, $result);
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment