0

ファイルを Safari でダウンロードできるようにしようとしています。これは私のコードです:

<?php
$file = $_GET['file'];
header ("Content-Disposition: attachment");
header ("Content-type: application/octet-stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>

FF では正常に動作しますが、Safari では 0kb ファイルを取得します。

送信しているヘッダーに何か問題があると思います。エラーは何ですか?

4

1 に答える 1

5

これを試して。

<?php
$file = $_GET['file'];
header('content-type: application/octet-stream');
header('content-Disposition: attachment; filename='.$file);
header('Pragma: no-cache');
header('Expires: 0');
readfile($file);
?>

注意:$_GET['file']衛生設備や制限なしに依存することは非常に危険です。サーバーアプリケーション全体を危険にさらすために使用できます!

于 2012-07-30T17:33:48.940 に答える