Download a text file instead of opening in a browser

I have one text file:

When I click Download , it should download and save it in my local download path.

I tried.

window.open("data.txt"); 

and

 header("Location:data.txt") 

But both of them open a text file browser. I upload a txt file.

Anyone please help me ..

thanks

Manikandan.

+7
source share
5 answers

http headers can solve your problem, just referr

  http://en.wikipedia.org/wiki/List_of_HTTP_header_fields 
+4
source

Try the following:

 $file = "data.txt"; $text = file_get_contents($file); header("Content-Disposition: attachment; filename=\"$file\""); echo $text; 
+5
source

Can you use this jquery plugin http://jdownloadplugin.com/ to download the file. It has many additional interesting features for downloading files from the Internet.

0
source

if you are using apache and want to force download the txt files instead of opening them in a browser. you can do it with .htaccess

 AddType application/octet-stream .txt 
0
source

I can tell you that you need to set the contents of the header header as a file attachment, but I do not know how to do this from JavaScript.

-one
source

All Articles