0

I use the following to convert a doc file to pdf in PHP:

function CallToApi($fileToConvert, $pathToSaveOutputFile, $apiKey, &$message,$unique_filename)
{
    try
    {


        $fileName = $unique_filename.".pdf";

        $postdata =  array('OutputFileName' => $fileName, 'ApiKey' => $apiKey, 'file'=>"@".$fileToConvert);
        $ch = curl_init("http://do.convertapi.com/word2pdf");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
        $result = curl_exec($ch); 
        $headers = curl_getinfo($ch);

        $header=ParseHeader(substr($result,0,$headers["header_size"]));
        $body=substr($result, $headers["header_size"]);

        curl_close($ch);
        if ( 0 < $headers['http_code'] && $headers['http_code'] < 400 ) 
        {
            // Check for Result = true

            if (in_array('Result',array_keys($header)) ?  !$header['Result']=="True" : true)
            {
                $message = "Something went wrong with request, did not reach ConvertApi service.<br />";
                return false;
            }
            // Check content type 
            if ($headers['content_type']<>"application/pdf")
            {
                $message = "Exception Message : returned content is not PDF file.<br />";
                return false;
            }
            $fp = fopen($pathToSaveOutputFile.$fileName, "wbx");

            fwrite($fp, $body);

            $message = "The conversion was successful! The word file $fileToConvert converted to PDF and saved at $pathToSaveOutputFile$fileName";
            return true;
        }
        else 
        {
         $message = "Exception Message : ".$result .".<br />Status Code :".$headers['http_code'].".<br />";
         return false; 
        }
    }
    catch (Exception $e) 
    {   
        $message = "Exception Message :".$e.Message."</br>";
        return false; 
    }
}

I now want to use the same to convert a ppt to pdf. For which I change

$ch = curl_init("http://do.convertapi.com/word2pdf"); 

to

$ch = curl_init("http://do.convertapi.com/PowerPoint2Pdf");

but I am not sure why it isnt converting the given input. Is there something that I may be missing?

AVM
  • 592
  • 2
  • 11
  • 25
Hardik Dave
  • 676
  • 1
  • 6
  • 17
  • Do you get any error? Please read response headers, they will contain additional data about exception. – Tomas Jun 18 '15 at 10:07

1 Answers1

0

It's due to PHP 5.6.

You need to add this line to your code as well

curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);

See:Backward incompatible changes (at the bottom).