From: diptimca at yahoo dot com Operating system: linux red had 9 PHP version: 4.3.8 PHP Bug Type: HTTP related Bug description: forces .php extension in the download dialog
Description: ------------ hi, i tried running the following code for downloading files. <?php // downloading a file use http://somewhere.com/download.php/?filename=name of file $filename = $_GET['filename']; if(!$filename){ echo "ERROR: No filename specified. Please try again."; } else { // fix for IE catching or PHP bug issue header("Pragma: public"); header("Expires: 0"); // set expiration time header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // browser must download file from server instead of cache // force download dialog header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. header("Content-Disposition: attachment; filename=".basename($filename).";"); header("Content-Transfer-Encoding: binary"); $root_path = "root path to image"; $myfile = $root_path . $filename; header("Content-Length: ".filesize($myfile)); readfile("$myfile"); exit(); } ?> It works well, but in the download dialog, it shows the filename of the php file in which this code is written. Even though i specify a txt file in myfile. please help me for the same . its urgent Reproduce code: --------------- <?php // downloading a file use http://somewhere.com/download.php/?filename=name of file $filename = $_GET['filename']; // a txt file or doc file if(!$filename){ echo "ERROR: No filename specified. Please try again."; } else { // fix for IE catching or PHP bug issue header("Pragma: public"); header("Expires: 0"); // set expiration time header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // browser must download file from server instead of cache // force download dialog header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. header("Content-Disposition: attachment; filename=".basename($filename).";"); header("Content-Transfer-Encoding: binary"); $root_path = "root path to image"; $myfile = $root_path . $filename; header("Content-Length: ".filesize($myfile)); readfile("$myfile"); exit(); } ?> Expected result: ---------------- in the download dialog, the default file name should be the one got form get method i.e "hello.txt" -- Edit bug report at http://bugs.php.net/?id=29807&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29807&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29807&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29807&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=29807&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29807&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29807&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29807&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29807&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29807&r=support Expected behavior: http://bugs.php.net/fix.php?id=29807&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29807&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29807&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29807&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29807&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29807&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29807&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29807&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29807&r=float