Code PHP without PEAR

95 views
Skip to first unread message

raphox

unread,
Feb 10, 2012, 11:30:49 AM2/10/12
to JODConverter
Hy guys,

hello guys,

I saw the old site an example of PHP code for connecting to
Webservice. But unfortunately, the code uses a PEAR package, that
sometimes makes it difficult for users.
So I made a version using CURL (native PHP), so most users can they
use the biblitoteca.
If you want to publish on the site, feel free. Not be necessary to
assign copyright if no interest.

Thank you.

<?php

class DocumentConverterClient {

var $url = "http://localhost:8080/converter/service";

function convert($inputData, $inputType, $outputType) {
$tuCurl = curl_init();

curl_setopt($tuCurl, CURLOPT_URL, $this->url);
curl_setopt($tuCurl, CURLOPT_POST, true);
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $inputData);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array("Content-Type: " .
$inputType, "Accept: " . $outputType, "Content-length: " .
strlen($inputData)));

$tuData = curl_exec($tuCurl);

curl_close($tuCurl);

if(curl_errno($tuCurl)){
throw new Exception(curl_error($tuCurl));
}

return $tuData;
}
}

$documentConverter = new DocumentConverterClient();

$inputFile = "document.odt";
$inputType = "application/vnd.oasis.opendocument.text";
$outputFile = "document.pdf";
$outputType = "application/pdf";

$outputData = $documentConverter-
>convert(file_get_contents($inputFile), $inputType, $outputType);
file_put_contents($outputFile, $outputData);

?>
Reply all
Reply to author
Forward
0 new messages