Reputation: 1594
i have one text file:
When i click the Download it should download and save it in my local download path.
I have tried.
window.open("data.txt");
and
header("Location:data.txt")
But both are open the text file browser it self. I what download the txt file.
Any one please help me..
Thanks
Manikandan.
Upvotes: 7
Views: 11914
Reputation: 1827
http headers may solve your problem, just referr
http://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Upvotes: 4
Reputation: 11490
if you are using apache and want to enforce downloading the txt files instead of opening them in browser. you can do using .htaccess
AddType application/octet-stream .txt
Upvotes: 0
Reputation: 1296
Try this:
$file = "data.txt";
$text = file_get_contents($file);
header("Content-Disposition: attachment; filename=\"$file\"");
echo $text;
Upvotes: 7
Reputation: 3217
Can you use this Jquery plugin http://jdownloadplugin.com/ to do the file download. It has many additional cool features for file downloading from web.
Upvotes: 0
Reputation: 613
I can tell you that you need to set header content-disposition as file attachment, but I do not know how to do it from JavaScript.
Upvotes: -1