After reading the php.net’s header manul, I wrote the scripts named
download_page.php, it worked. That is, when a visitor clicked the link to the download_page.php, the file-save dialog was shown, and the file “MyProgram.exe”
was downloaded.
Below scripts is named as “download_page.php”
<?
$size=filesize(“MyProgram.exe”);
header(“Content-Type: application/exe”);
header(“Content-Disposition: attachment; filename=MyProgram.exe”);
header(“Content-Length: $size”);
header(“Cache-control: private”);
$filename=“MyProgram.exe”;
$fp =fopen($filename, ‘r’);
fpassthru($fp);
header(“Location: MyProgram.exe”);
?>
I have 2 questions.
-
the for-download file name shown on the prompted file-save dialog
is “download_page.php”, not “MyProgram.exe”,
How can resolve this error? -
header(“Location: MyProgram.exe”);
Is this line really needed in the download_page.php?
Thanks for any help!