TomT Posted September 22, 2009 Share Posted September 22, 2009 Hi I have a web page that runs a back end script and then presents the user with a hyperlink to a dynamically generated txt file. (the name is based on date & time) All the backend bits are working fine, its just the downloading of the text file.. The hyperlink is similar to: <a href="/admin/file 11.08.09 140954.txt">Click HERE</a> How do I force the hyperlink to prompt for the save dialogue box and not open the txt file within the browser ?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/175119-save-not-view-txt-file/ Share on other sites More sharing options...
Bricktop Posted September 22, 2009 Share Posted September 22, 2009 Hi TomT, Have a look at this article http://davidwalsh.name/php-force-download But the link you showed above should bring up a save dialog. If your link is something like: download.php?&file=blah.txt then you can have problems saving files from hyperlinks but your link should work, have you tried the same link on another machine/in a different browser? Quote Link to comment https://forums.phpfreaks.com/topic/175119-save-not-view-txt-file/#findComment-922967 Share on other sites More sharing options...
samshel Posted September 22, 2009 Share Posted September 22, 2009 try adding urlencode() for the file name. Quote Link to comment https://forums.phpfreaks.com/topic/175119-save-not-view-txt-file/#findComment-922996 Share on other sites More sharing options...
Raphael diSanto Posted September 22, 2009 Share Posted September 22, 2009 Like it says in the article posted by Bricktop, you can't force a download with a simple <a href> link. The browser's default behavior for that type of file will always take priority. To force a download, you need to direct the user to a script that sends the right headers, and then reads the file from the server and streams it to the browser. The article shows you how to do this. Quote Link to comment https://forums.phpfreaks.com/topic/175119-save-not-view-txt-file/#findComment-923032 Share on other sites More sharing options...
TomT Posted September 23, 2009 Author Share Posted September 23, 2009 Thanks. I'll have a read Quote Link to comment https://forums.phpfreaks.com/topic/175119-save-not-view-txt-file/#findComment-923384 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.