1

I searched online about this meta refresh code in html

<META HTTP-EQUIV='REFRESH' CONTENT='5;URL=http://www.example.com/test.txt'>

this code redirects the page to http://www.example.com/test.txt after 5 seconds..

i wanted it to download the file! not opening it in the browser!,

some extensions doesn't download using this code, like ( js jpg html css.. etc.. ),

the browser just open them!, well i want the browser to download not to open,

Does anybody know how?

Tarık Seyceri
  • 435
  • 2
  • 9
  • 16

1 Answers1

5

You need your server to send the HTTP header Content-Disposition: attachment along with the file you want to download rather than display in the browser. How you do this depends entirely on what server software you're using.

For example with on an Apache server with mod_headers enabled, you'd add something like this to the .htaccess file in your web root directory:

<Files "test.txt">
    ForceType text/plain
    Header set Content-Disposition "attachment"
</Files>

For other software you can check the documentation.

In addition, it's possible to load and stream the file, with the correct headers, with a very simple PHP script like this one: https://stackoverflow.com/a/20080402/1546831

Community
  • 1
  • 1
Adrien Delessert
  • 1,360
  • 12
  • 17