25 September 2008

PHP Code - Forcefully Download A file

//header('Content-Type: application/pdf');

if($_GET['fol']=='pdf')
{
$filename = "desa/".$_GET['name'];
header('Content-Type: application/pdf');
}
else
{
$filename = "ppt/".$_GET['name'];
header('Content-Type: application/ppt');

}

if(isset($_GET['name1']) and $_GET['name1']='archives')
{
$filename = "archives/".$_GET['name'];
header('Content-Type: application/pdf');
}

header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
@readfile("$filename") or die("File not found.");

?>

No comments: