ダウンロードをストリーミングして、サーバーからファイルをダウンロードしようとしています。
これは私のスクリプトです:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=http://user:pass@example.com/file.bin';
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $r[2]);
ob_clean();
flush();
readfile($fileName);
exit;
example.comは私が実際に使用しているものではなく、実際のURLを表示したくなかっただけです。:) Webブラウザでこのファイルにアクセスすると、ダウンロードプロンプトが表示されず、何も起こりません。$r[2]
はファイルのコンテンツの長さ(バイト単位)であり$fileName
、添付ファイルヘッダーで使用されているものと同じURLです。何が間違っているのか本当にわかりません。