RE: [PHP-GENERAL] downloading files

From: Date: Fri, 09 Jun 2000 05:13:54 +0000
Subject: RE: [PHP-GENERAL] downloading files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1366@lists.php.net to get a copy of this message
Hi Bill, Bill Rausch Wrote: > I've written the getfile.php script to get the file from the backend to the > web server machine, and then hand it to the browser using: > ... // get file from backend into tmp directory on web server > ... > header( "Location: http://hostname/tmp/$filename" ); > > The question I have is how can I control the downloaded file's name. > Instead of being named, for example, demo.ppt, it is saved by the client's > browser as getfile.php. > > Is there a completely better way to be doing this? You can send a content-disposition header. header("Content-Disposition: attachment; filename=".$myFileName); Note, the attachment directive is there to force IE to download the file and not attempt to display it in the browser (IE ignores content-type). So strictly speaking, you don't need it to just set the filename. Also unless your doing it for other reasons you don't need to place the file in a temp directory and redirect the browser, you can just read the file from it's stored location and send it straight to the browser. eg. <? header("Content-Type: application/vnd.ms-powerpoint"); header("Content-Disposition: attachment; filename=".$file); readfile($path.$file); ?> Andrew

« previous php.general (#1366) next »