Re: Download function for php

From: Date: Mon, 09 Jul 2001 15:34:36 +0000
Subject: Re: Download function for php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-56941@lists.php.net to get a copy of this message
Mark Lo wrote: > > Hi, > > Is there any php download function for php. I am asking is the one like > downloading the file from the server when people click the link. Like > downloading php sources tar file. > > Thank you > > Mark No download function that I know of, but it isn't hard to download. The trick is to send out a Content-Type header with the Mime type, an optional Content-disposition to suggest a name and then whatever it is you want to download. e.g. to download some data in tab-delimited format - header("Content-type: text/tab-separated-values"); header("Content-disposition: inline; filename=".$myfilename); while(... { print "\t$field1\t$field2\t$field3\t$field4\n"; } exit; You can download any mime type, so it could just as well be downloading a text file, a word-processor document, an image, a Shockwave file or whatever. You can easily use readfile to pick up the contents of an existing file. If you find the browser is trying to get too clever when it spots the Mime type, you can always make up your own, which should force it to just offer a save. Hope that helps. George

« previous php.general (#56941) next »