I have in the achive found some examples to download make a viewer download a file but have not been able to make it work satisfying.
This code shows the contents of the file in the web browsers frame:<?php
if (($REQUEST_METHOD != "GET") or empty($name))
{
Header("Location: /");
exit;
}
// Hack for IE-bug
if (strstr($HTTP_USER_AGENT, "MSIE"))
$attachment = "";
else
$attachment = " attachment;";
$size = filesize("$name");
//print "filename is $name and size is $size<BR>";
if($newfile=fopen($name,"r"))
{
header("Content-disposition: inline; filename=".ereg_replace ("(.+[\/\])([\/\]+$)", "\2", $name));
header("Content-type: application/x-ms-download");
//header("Content-Length: $size");
//header("Content-Transfer-Encoding: binary");
fpassthru($newfile);
}
?>
Following code tries to download a file with the same name as the php file without extensions:
<?php
if (($REQUEST_METHOD != "GET") or empty($name))
{
Header("Location: /");
exit;
}
// Hack for IE-bug
if (strstr($HTTP_USER_AGENT, "MSIE"))
$attachment = "";
else
$attachment = " inline;";
$size = filesize("$name");
$fh = fopen("$name", "r");
header("Content-Type: application/x-ms-download");
header("Content-Length: $size");
header("Content-Disposition:$attachment filename=$name");
header("Content-Transfer-Encoding: binary");
fpassthru($fh);
exit;
?>
Where do I go wrong? I have no more ideas myself. Anyone?