Suppose there is a file that is displayed on the page using headers:
header("Content-Length: " . filesize($file) );
header(“Content-type: application/pdf”);
header(“Content-disposition: inline”);
header(‘Expires: 0’);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’);
How can I download that file externally, using curl or file_get_contents or in any other way?
I tried this but it downloads an empty file:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url); //specify the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$body = curl_exec($ch);
header(‘Content-Disposition: attachment; filename=“downloaded.pdf”’);
header("Content-Length: " . strlen($body));
header(“Content-Type: application/octet-stream”);
echo $body;
Can anyone help?