Welcome
I have a little problem saving the downloaded pdf on the page. To download pdf, I use Curl:
$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);
Now in $ Result (line) I have all the contents of the PDF file. And now my problem begins. I would like to save the downloaded pdf:
header('Cache-Control: public');
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="new.pdf"');
header('Content-Length: '.filesize($Result));
readfile($Result);
Unfortunately, when I save or open a new PDF file, I get a blank document. Perhaps the problem is with the last lines:
header('Content-Length: '.filesize($Result));
readfile($Result);
Unfortunately, I do not know how to change them in order to make it work ... I ask you for help. Thanks
source
share