phpconvertapi

ConvertAPI/PHP code upload/download 0 bytes


I'm trying to call the ConvertAPI RESTful API using PHP/CURL to convert a form upload PDF to PNG. The file upload is working as the file is showing up on the server, but nothing is returned with curl_getinfo showing [size_upload] => 0 and [size_download] => 0. Can someone point out the error in my code?

define("UPLOAD_DIR", "./tmp/");
$rest_url="https://do.convertapi.com/Pdf2Image";

$up_file=UPLOAD_DIR.rand(100,999)."_".basename($_FILES['fileField']['name']);
if (!move_uploaded_file($_FILES['fileField']['tmp_name'], $up_file)) {
    die("Possible file upload attack!");
}

$cfile=new CURLFile($up_file);

$params=array(
    "ApiKey" => 11111111,
    "OutputFormat" => "png",
    "OutputFileName" => "converted.png",
    "File" => $cfile
    );

$ch=curl_init($rest_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$res=curl_exec($ch);
$headers=curl_getinfo($ch);
curl_close($ch);

echo "<pre>";
print_r($headers);
var_dump($res);

Solution

  • The upload stops if the URL is written with https://. It should be http:// instead (without the SSL).

    Use this:

        $rest_url="http://do.convertapi.com/Pdf2Image";
    

    Instead of:

        $rest_url="https://do.convertapi.com/Pdf2Image";