Hi all,
I have ms word files in a database table. When I download via webpage on my site the document fails to appear. Either the page freezes or I get alert box message.
Here's the download code:
<?php
session_start();
?>
<?
if(isset($_GET['id']))
{
@ $db = mysql_connect('localhost', 'cml', 'chl');
if (!$db)
{
echo 'Sorry. Could not connect to database. Please try again later.<br />';
exit;
}
mysql_select_db('projects') or die(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);
// header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
// header('Content-Type: application/force-download');
header('Content-Type: application/msword');
header('Content-Disposition: inline; filename=$name');
echo $content;
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transational//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Project Download</title>
<link rel="stylesheet" type="text/css" href="../../style.css" />
</head>
<body>
<h1>Documents Available </h1>
<br />
<?
@ $db = mysql_connect('localhost', 'cil', 'cil');
if (!$db)
{
echo 'Sorry. Could not connect to database. Please try again later.<br />';
exit;
}
mysql_select_db('cilprojects') or die(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;?>" target="blank">
<?=$name;?>
</a><br />
<br />
<?
}
}
?>
Again the file doc names appear on download page. Only problem is downloading them.
I get the alert box saying "you are downloading $name from www.website.com"
How can I fix this please?
Thanks,
Kevin.