Re: Downloading files

From: Date: Sun, 23 Feb 2003 14:24:30 +0000
Subject: Re: Downloading files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-136723@lists.php.net to get a copy of this message
on 24/02/03 1:01 AM, Anthony Rodriguez (sbwi@bellatlantic.net) wrote: > In PHP, is there a way to allow the user to download a file (e.g.: > sample.txt) to their computer? And, then, automatically return to the > PHP-generated Web page. why do you need to re-run the page? it can be done with a bit of messing around, but i can't imagine why :) you can force the download of a file by setting the correct headers using header() and passing the file through. see the user notes on http://php.net/header. if you're only talking about text files, then why not simply do <a href='blah/sample.txt' target='_blank'>click</a> ??? This will pop it up in a new window, leave the original window untouched, and they can choose "save as" from the file menu. if for some reason you DO want the original window to be refreshed, this could easily be done with a javascript onclick event in the above <a> tag. > How can the file be stored in C:\sample.txt, for example? you have no control over where the user downloads the file to -- it's entirely up to them and/or their browser settings. actually, "forcing a download" really isn't true... in most cases your really "forcing a 'save file as...' dialogue window. Justin

« previous php.general (#136723) next »