Forcing page download in PHP

前端 未结 1 1123
忘了有多久
忘了有多久 2020-12-12 06:29

How do I force the browser to download the current page browsed to? A page with the header Content-type: text/plain for example using PHP?

If a user navigates to tha

相关标签:
1条回答
  • 2020-12-12 06:53

    Straight from http://php.net/header

    <?php
        // There is contention over if this MIME type is right, but just use it for now.
        header('Content-type: text/javascript');
    
        header('Content-Disposition: attachment; filename="file.js"');
    
        readfile('file.js'); // Echo the file
    ?>
    

    NOTE: this must be done before any other output (and can be about the only thing on the page, unless you want other output in your file).

    0 讨论(0)
提交回复
热议问题