Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/175119-save-not-view-txt-file/
Share on other sites

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.