Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to download this PDF file using php
    text
    copied!<p>I want to download a pdf file from <a href="https://www.sedi.ca/sedi/SVTReportsAccessController?menukey=15.03.00&amp;locale=en_CA" rel="nofollow">this link</a>. From the page, select weekly summary, I want download the first pdf.</p> <p><a href="https://www.sedi.ca/sedi/SVTWeeklySummaryACL?name=W1ALLPDFI&amp;locale=en_CA" rel="nofollow">PDF</a> Weekly summary - Last week: Sorted by insider</p> <p>I'm using the following code try to download the pdf,</p> <pre><code>&lt;?php $file="https://www.sedi.ca/sedi/SVTWeeklySummaryACL?name=W1ALLPDFI&amp;locale=en_CA"; if (file_exists($file)) { if (FALSE!== ($handler = fopen($file, 'r'))) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: chunked'); //changed to chunked header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); //header('Content-Length: ' . filesize($file)); //Remove //Send the content in chunks while(false !== ($chunk = fread($handler,4096))) { echo $chunk; } } exit; } echo "&lt;h1&gt;Content error&lt;/h1&gt;&lt;p&gt;The file does not exist!&lt;/p&gt;"; ?&gt; </code></pre> <p><strong>It seems I can not download using PHP. I can download by myself confirm the popup window. Any suggestions?</strong></p> <p>I tried curl also, still can not download. The file size is zero.</p> <pre><code>&lt;?php $file="https://www.sedi.ca/sedi/SVTWeeklySummaryACL?name=W1ALLPDFI&amp;locale=en_CA"; $path = 'c:\download\output.pdf'; $ch = curl_init($file); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); file_put_contents($path, $data); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload