Hi,
I want to download CSV file, and I have the following code.
The problem is I can not close the browser.
Step1:
on original.php
-> click [csv] button
-> open download_csv.php
Code1 (download_csv.php):
<?php
.......
header("Content-disposition: attachment; filename=" . $FileName);
header("Content-type: application/octet-stream; name=" . $FileName);
echo "test1,test1,test3 \r\n";
exit;
?>
This will popup message box, and asked me if I want to open CSV file or want to save. The problem is that I can not close a blank browser (download_csv.php). All code I wrote to close the window were printed on CSV file. It was treated as a text data, not a script.
To solve this problem, I changed steps.
Step2:
on original.php
-> click [csv] button
-> reload originai.php
**** write a code on the same file so that I do not need to close it.
Code2(original.php):
<?php
switch($_GET['act']) {
case 'download';
header("Content-disposition: attachment; filename=" . $FileName);
header("Content-type: application/octet-stream; name=" . $FileName);
echo "test1,test1,test3 \r\n";
break;
default:
<html>
<header>
<script language=javascript>
function go( purl ) {
.........
}
</script>
<body>
<form>
....... original contents ....
<input type="hidden" name="act" value="download">
<input type="button" value="OrgButton1" onclick=\"javascript:go('nextpage.php')\">
<input type="button" value="CSV" onclick=\"javascript:go('original.php')\">
</form>
</body>
</html>
} // end of switch
The problem for Step2 is that I can not user [OrgButton1] anymore. After I click [CSV] button and save csv file on my C: and click [OrgButton1] button to go nextpage, I got error. It said that "there is no access". I do not understand this.
Does anybody know which way is good and what I did wrong?
P.S.
I do not want to save a file on the server.