在PHP中强制页面下载

在PHP中强制页面下载,php,Php,如何强制浏览器下载浏览到的当前页面?标题内容类型为text/plain(例如使用PHP)的页面 如果用户导航到该页面,将出现一个下载框(浏览器下载对话框,通常为“另存为”。直接从 直接从 如果我下载的是一个js文件,那么url应该读像:www.site.file.js吗?如果我下载的是一个js文件,那么url应该读像:www.site.file.js吗? <?php // There is contention over if this MIME type is right, bu

如何强制浏览器下载浏览到的当前页面?标题内容类型为text/plain(例如使用PHP)的页面

如果用户导航到该页面,将出现一个下载框(浏览器下载对话框,通常为“另存为”。

直接从

直接从


如果我下载的是一个js文件,那么url应该读像:www.site.file.js吗?如果我下载的是一个js文件,那么url应该读像:www.site.file.js吗?
<?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
?>