i've a news system script, and i give to users the possibility to download pdf and doc files.
the first problem is, when i click on pdf files, browser open its. i need to download pdf not open.
second problem is, when i download doc files and open into msword, the file results unreadable.
this is the script:
Code: Select all
<?php
include("dbconnect.php");
switch($_GET['type']) {
case 'pdf':
$query = "SELECT DatiBinari, Nome, Type FROM pdf WHERE id_sharepdf = '{$_GET['Id']}'";
break;
case 'doc':
$query = "SELECT DatiBinari, Nome, Type FROM doc WHERE id_sharedoc = '{$_GET['Id']}'";
break;
default:
echo "Dati non corretti";
exit;
break;
}
$result = mysql_query($query) or die(mysql_error());
if($result) {
$ris = mysql_fetch_assoc($result);
// INTERNET EXPLORER
if(ereg("MSIE ([0-9].[0-9]{1,2})", $_SERVER["HTTP_USER_AGENT"])) {
header("Content-Type: {$ris['Type']}");
header("Content-Disposition: inline; filename={$ris['Nome']}");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
} else {
header("Content-Type: {$ris['Type']}");
header("Content-Disposition: attachment; filename={$ris['Nome']}");
header("Expires: 0");
header("Pragma: no-cache");
}
}
echo $ris['DatiBinari'];
exit;
?>thanks