Re: PHP - Forced header downloads

From: Date: Wed, 20 Mar 2002 02:37:09 +0000
Subject: Re: PHP - Forced header downloads
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-89261@lists.php.net to get a copy of this message
On Tue, 19 Mar 2002, Ian Wayne wrote: > I'm trying to use some header functions to force the browser to download > quicktime movies. I have a small piece of code that takes the relevant file > name from the url and then uses that in the header function. This code sits > in get.php. Unfortunately, all I download when I click the link is get.php. > Although the name is changed to the desired file name (eg 193430239.mov). Let me know if this link works for you (works for me in both IE and lynx): http://u.nu/test/download-intro.html Here's the code I used (stolen liberally from yours): <? // clean up file name $file = preg_replace( array('/^\//', '/\.\.+/', '/[^a-zA-Z0-9\.\-_ ]/', '/\.php\b/'), '', $PATH_INFO); if (is_readable($file)) { header("Content-type: application/octet-stream\n"); header("Content-disposition: attachment; filename=\"$file\"\n"); header("Content-transfer-encoding: binary\n"); header("Content-length: ".filesize($file)."\n"); readfile($file); } ?> miguel

« previous php.general (#89261) next »