Page 1 of 1

Download script shows filename.ext.php

Posted: Mon Nov 10, 2003 12:14 am
by rampradeep1
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);
-------------------------------------------------------------------------------------

Posted: Mon Nov 10, 2003 4:13 am
by JayBird
i use this script, give it a try

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);

?>
Obviously chage the Content types and paths to suit.

Mark