0

DialogBox(開く/保存)を表示せずにファイルを強制的にダウンロードする方法を誰かが知ることができますか?以下のコードは、作成したExcelファイルをダウンロードするためのテストスクリプトですが、ダイアログボックスにファイルをダウンロードするように表示されます。

$filename ="excelreport.xls";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;

ファイルを自動的にダウンロードして、ダイアログボックスなしで指定したディレクトリに保存したい

4

2 に答える 2

2

表示する代わりに強制的にダウンロードすることもできますが、一般的にブラウザにプロンプ​​トなしで強制的にダウンロードさせることはできないと思います。

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache

// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

ソース:php.net

于 2012-10-23T12:08:23.623 に答える
1

セキュリティ上の理由から、これを行うことはできません。

于 2012-10-23T12:09:57.420 に答える