Download script shows filename.ext.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rampradeep1
Forum Newbie
Posts: 1
Joined: Mon Nov 10, 2003 12:14 am

Download script shows filename.ext.php

Post 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);
-------------------------------------------------------------------------------------
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Post Reply