$docid = $_GET['docid'];
if ($docid)
{
//Open Database
include "functions.php";
$db=opendb();
$sql="SELECT * FROM docs where docid='".$docid."'";
//echo $sql."
";
$result = mysql_query($sql);
if (mysql_errno()) {echo mysql_errno().": ".mysql_error()."
";}
if ($myrow=mysql_fetch_array($result))
{
$document=$myrow['document'];
$format=$myrow['format'];
$title=$myrow['title'];
$filename=$myrow['docname'];
if (($format=="text/html")OR($format=="image/pjpeg")OR($format=="image/gif") )
{
header("Content-Type: $format");
header("Content-Disposition: inline; filename=$filename");
}
else if ($format=="application/pdf")
{
if ($filename==''){$filename='download.pdf';}
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=$title");
}
else if ($format=="application/x-pdf")
{
if (!$filename){$filename='download.pdf';}
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=$filename");
}
else if ($format=="text/plain")
{
nl2br($document);
}
else if ($format=="text/richtext")
{
header("Content-Type: $format; ");
header("Content-Disposition: inline; filename=$filename");
}
else if (($format=="application/msword") OR ("application/vnd.ms-excel"))
{
header("Content-Type: $format; ");
header("Content-Disposition: inline; filename=$filename");
}
else if ($format=="application/octet-st") //rtf
{
header("Content-Type: $format; ");
header("Content-Disposition: inline; filename=$filename");
}
else
{
header("Content-Type: application/ms-x-download");
header("Content-Disposition: attachment; filename=$title");
header("Content-Transfer-Encoding: binary");
}
echo $document;
}
};
?>