Page 2 of 2

Posted: Fri Jan 19, 2007 5:48 pm
by aaronhall
Try switching out the content-type:

application/x-msexcel
application/ms-excel
application/msexcel
application/x-excel

Try commenting it out too.

Posted: Fri Jan 19, 2007 6:19 pm
by gerryjuice
commenting out

Code: Select all

header("Content-type: $type");
has no effect on the current issue.
As far as i know type of the file is picked up by

Code: Select all

$fileType = $_FILES['userfile']['type'];
Changing the application type as suggested before calling

Code: Select all

echo $content
makes no difference.

Is there a simpler way to do this, or am i missing something.

Posted: Fri Jan 19, 2007 6:34 pm
by aaronhall
And you tried quotes around $name in Content-Disposition

Posted: Sat Jan 20, 2007 9:07 am
by gerryjuice
Put "" around the $name variable in

Code: Select all

header("Content-Disposition: attachment; filename=$name");
Which resulted in nothing coming out on the page at all. Does this mean an error occured.

Here is my code currently:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<title>Download File From MySQL</title> 
	</head> 
	
	<body> 
	<?
	if(isset($_GET['id'])) 
	{ 
		include("db.inc.php"); 
			mysql_connect($databaseServer,$user,$passwd) or
		  die("Could not connect to the database.<br>".mysql_error());
			  mysql_select_db($database) or 
		  die("Could not select your database.<br>".mysql_error());
	
		$id      = $_GET['id']; 
		$query   = "SELECT name, type, size, content FROM upload WHERE id = '$id'"; 
		$result  = mysql_query($query) or die('Error, query failed'); 
		list($name, $type, $size, $content) = mysql_fetch_array($result); 
		echo $name;
		echo $type;
	
		
		header('Pragma: private');
		header('Cache-control: private, must-revalidate');
		header('Content-Transfer-Encoding: Binary'); 
		header('Content-Type: application/octet-stream; filename=$name');
		header("Content-Disposition: attachment; filename=$name"); 
		//header("Content-length: $size"); 
		//header("Content-type: $type"); 
		echo $content; 
		//echo ("Content-Disposition: attachment; filename=$name"); 
		//echo ("Content-length: $size"); 
		//echo ("Content-type: $type"); 
		mysql_close();  
		exit; 
	} 
	 
		include("db.inc.php");
		mysql_connect($databaseServer,$user,$passwd) or die("Could not connect to the database.<br>".mysql_error());
		mysql_select_db($database) or die("Could not select your database.<br>".mysql_error());
	
		$query  = "SELECT id, name FROM upload"; 
		$result = mysql_query($query) or die('Error, query failed'); 
		if(mysql_num_rows($result) == 0) 
		{ 
			 echo "Database is empty <br>"; 
		 }  
		  else 
		 { 
			 while(list($id, $name) = mysql_fetch_array($result)) 
		  { 
	?> 
		<a href="download.php?id=<?=$id;?>"><?=$name;?></a> <br> 
	<?         
		} 
	} 
		mysql_close();
	?> 
	</body> 
	</html>

Posted: Sat Jan 20, 2007 2:59 pm
by aaronhall

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <title>Download File From MySQL</title>
        </head>
       
        <body> 
The headers probably aren't being sent because this is being outputted to the browser. Only display this if the user isn't download the file.

Code: Select all

header('Content-Type: application/octet-stream; filename=$name');
That needs to be in double-quotes, and I'm not even sure that the filename belongs in the content-type header.

Posted: Sat Jan 20, 2007 3:49 pm
by daedalus__
I was just going to mention that, I feel retarded because I hadn't pointed that out earlier.

Please make sure that PHP is reporting all errors.