Re: downloading winword & mp3 files the fancy way through a browser

From: Date: Wed, 26 Aug 2009 15:09:46 +0000
Subject: Re: downloading winword & mp3 files the fancy way through a browser
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-297284@lists.php.net to get a copy of this message
On Wed, Aug 26, 2009 at 03:38:27PM +0200, Grega Leskov??ek wrote: > I tried to download the file from another server the fancy way in PHP, but > it just display blank screen. Can You please look at my code: If it helps, here is some code that I dug up from an old project: <?php $filepath = "/var/www/test.doc"; $filename = basename($filepath); $filesize = filesize($filepath); if ( file_exists($filepath) ) { header("Cache-Control: no-store, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Content-Transfer-Encoding: binary"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-disposition: attachment; filename=" . $filename); header("Content-length: " . $filesize); $fh = fopen($filepath, "rb") or exit("Could not open file."); while (!feof($fh)) { print(fgets($fh,4096)); } fclose($fh); } else { echo "The file does not exist."; } ?> I would also verify that the web server has permissions to the files that php is trying to open. Internet Explorer 8 seems to have a problem with the filename parameter in the Content-disposition header being enclosed in quotes. It would just dump the binary data in the page when I was testing this. Regards, Ryan

« previous php.general (#297284) next »