Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  98] [ 6]  / answers: 1 / hits: 21849  / 12 Years ago, sun, march 4, 2012, 12:00:00

Let's say I have this file on my server:



server/myFile.txt


How can I make the user download it with a button click?
Am I missing a simple solution?



I am using jQuery & PHP if there is a solution for that.



thanks,
Alon


More From » php

 Answers
19

If you want to force a save-as dialog box to open for a file type that your web server is configured to output as a readable document (and you don't want to change that configuration), you need to create a file that modifies the headers so that the browser creates such a dialog.



See the very first example in the php documentation for readfile.



You would then create a PHP file that could be accessed through a normal a href link, which would send the appropriate headers and output myFile.txt.


[#87058] Friday, March 2, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
turnerf

Total Points: 620
Total Questions: 101
Total Answers: 109

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
turnerf questions
;