title: PHP + PDF, how to save a downloaded PDF using curl?
body: <p>Welcome</p>
  
  <p>I have a little problem with saving the downloaded pdf on the page. To download pdf I use Curl:</p>
  
  <pre><code>$CurlConnect = curl_init();
  curl_setopt($CurlConnect, CURLOPT_URL, 'http://website.com/invoices/download/1');
  curl_setopt($CurlConnect, CURLOPT_POST,   1);
  curl_setopt($CurlConnect, CURLOPT_RETURNTRANSFER, 1 );
  curl_setopt($CurlConnect, CURLOPT_POSTFIELDS, $request);
  curl_setopt($CurlConnect, CURLOPT_USERPWD, $login.':'.$password);
  $Result = curl_exec($CurlConnect);
  </code></pre>
  
  <p>Now in <b>$Result</b>(string) i have all PDF file content. And now begins my problem. I would like to save the downloaded pdf:</p>
  
  <pre><code>header('Cache-Control: public'); 
  header('Content-type: application/pdf');
  header('Content-Disposition: attachment; filename="new.pdf"');
  header('Content-Length: '.filesize($Result));
  readfile($Result);
  </code></pre>
  
  <p>Unfortunately, when I save or open a new PDF file, I get a blank document. Perhaps the problem is with the last lines of:</p>
  
  <pre><code>header('Content-Length: '.filesize($Result));
  readfile($Result);
  </code></pre>
  
  <p>Unfortunately, I do not know what to change them to make it work ... I ask for your help. Thanks</p>