このリンクからPDFファイルをダウンロードしたい。ページから、週ごとの要約を選択します。最初のpdfをダウンロードします。
PDF ウィークリーサマリー-先週:インサイダーでソート
次のコードを使用してPDFをダウンロードしてみてください。
<?php
$file="https://www.sedi.ca/sedi/SVTWeeklySummaryACL?name=W1ALLPDFI&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 "<h1>Content error</h1><p>The file does not exist!</p>";
?>
PHPではダウンロードできないようです。ポップアップウィンドウを確認して自分でダウンロードできます。助言がありますか?
カールも試してみましたが、まだダウンロードできません。ファイルサイズはゼロです。
<?php
$file="https://www.sedi.ca/sedi/SVTWeeklySummaryACL?name=W1ALLPDFI&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);
?>