tags:

views:

37

answers:

1

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 that page, a download box should appear (the browser download dialog with the usual "Save As"

+1  A: 

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).

Also, there's a billion dupes of this question on Stack Overflow. Too lazy to copy pasta them all.

Dan Beam
if I am downloading a js file, should the url read something like: www.site.file.js?
Ygam
edited post for you with your new data
Dan Beam