I am using following code for downloading files. Its working fine in IE. But in Netscape while saving the file. in the file dialog, it shows filename.ext.php. How to remove this ".php" from the saveas file name.
--------------------------------------------------------------------------------------
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=\"" . $file_name . "\"");
header("Content-Length: " . filesize ($download_this));
header("Content-Transfer-Encoding: binary");
fpassthru($fp);
$fd = fopen($download_this ,'r');
$contents = fread ($fd, filesize ($file_name));
echo $contents;
fclose ($fp);
-------------------------------------------------------------------------------------
Download script shows filename.ext.php
Moderator: General Moderators
-
rampradeep1
- Forum Newbie
- Posts: 1
- Joined: Mon Nov 10, 2003 12:14 am
i use this script, give it a try
Obviously chage the Content types and paths to suit.
Mark
Code: Select all
<?
// Get the filename from the query string of the file we want to download
$fileName = $HTTP_GET_VARS["file"];
// The full path to our downloads directory
$fileDir = "/full/path/";
// Combine the filename and the path
$path = "$fileDir$fileName";
////////////////////////////////////////
/* Force browser to download the file */
////////////////////////////////////////
global $HTTP_USER_AGENT;
$file = basename($path);
$size = filesize($path);
header("Content-Type: application/octet-stream");
header("Content-Type: application/pdf");
header("Content-Length: $size");
// IE5.5 just downloads index.php if we don't do this
if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {
header("Content-Disposition: filename=$file");
} else {
header("Content-Disposition: attachment; filename=$file");
}
header("Content-Transfer-Encoding: binary");
$fh = fopen($path, "r");
fpassthru($fh);
?>Mark