Reputation: 1241
can anyone know on how could I force to download a file without displaying DialogBox (Open/Save). The below code was is my test script to download created excel file but the dialog box appears to download a file.
$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;
I want to automatically download file and save it on specified directory without dialog box
Upvotes: 0
Views: 1573
Reputation: 1393
You can force to download instead of showing it but I think it is not possible to force the browser in general to download it without a prompt
// 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");
Source: php.net
Upvotes: 2