Force Download Only Displays in Browser, Doesn't Prompt for Download

前端 未结 2 1059
孤独总比滥情好
孤独总比滥情好 2020-12-20 04:20

I can\'t seem to figure this out and I know it\'s something simple. I am building the back-end to a very basic content management system. For this specific piece, I am jus

相关标签:
2条回答
  • 2020-12-20 04:51

    I think the problem can be that there is some whitespace somewhere in the PHP files, which causes that the headers are not sent correctly and therefore you see the whole output.

    I would suggest the followings steps:

    1. check the "connect.php" and look for empty lines/spaces at the begining/ending of the file and remove them

    2. adapt you php files that way, that you leave out the ending tag ?> at the end of the file - that way you do not get empty lines at the end of the file

    3. if the above are not enough you need to check your apache and php error log and/or set up error loging, so you see also warnings - that you you would be informed if the headers are not sent correctly or if there is some other error

    0 讨论(0)
  • 2020-12-20 04:53

    Headers I use for download:

            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header("Content-type: application/force-download");
            header("Content-Disposition: attachment; filename=".$file); 
            header("Content-Type: application/octet-stream");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".$bytes."");
    
    0 讨论(0)
提交回复
热议问题