na een eerder topic (met een terecht slotje) nu een nieuw topic met hierin mijn code en dergelijke.
Ik ben met een website bezig en wil hier in mensen gelegenheid geven om .doc files en .pdf files te downloaden.
Nu heb ik de volgende code's:
de code van de formulieren pagina
------------------------------------------------------------------------------------------------------------
<title>formulieren</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<style type="text/css">
H1 { font-family:"Times New Roman", Times, serif; font-size:26px }
H2 { font-family:"Times New Roman", Times, serif; font-size:14px }
</style>
<body>
<? echo("
<h1>Formulieren:</h1>
<H2>
Lidmaatschap aanvraag (download pdf) ") ?> <a href="index.php?file=downloads/aanmelding.doc" style="color:#000000">(download word)</a><br>
<? echo("
Lidmaatschap mutatie (download pdf) (download word)
</H2>
")
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------
in deze pagina moeten de bezoekers dus een link aan kunnen klikken en de file kunnen downloaden.
verder heb ik de downloadpagina met het volgende script:
------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>download</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$filename = $_GET['file'];
$file-extension = substr( $filename,-3 );
if( $filename == "" )
{
echo "<html><title>Download mislukt</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
exit;
} elseif ( ! file_exists( $filename ) )
{
echo "<html><title>Download mislukt</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
exit;
};
switch( $file-extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type: $ctype");
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win"))))
{
header( "Content-Disposition: filename=".basename($filename).";" );
} else {
header( "Content-Disposition: attachment; filename=".basename($filename).";" );
}
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------
Ik krijg dit niet werkende.
alleen zie ik in de code geen fout ??
Ik ben met een website bezig en wil hier in mensen gelegenheid geven om .doc files en .pdf files te downloaden.
Nu heb ik de volgende code's:
de code van de formulieren pagina
------------------------------------------------------------------------------------------------------------
<title>formulieren</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<style type="text/css">
H1 { font-family:"Times New Roman", Times, serif; font-size:26px }
H2 { font-family:"Times New Roman", Times, serif; font-size:14px }
</style>
<body>
<? echo("
<h1>Formulieren:</h1>
<H2>
Lidmaatschap aanvraag (download pdf) ") ?> <a href="index.php?file=downloads/aanmelding.doc" style="color:#000000">(download word)</a><br>
<? echo("
Lidmaatschap mutatie (download pdf) (download word)
</H2>
")
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------
in deze pagina moeten de bezoekers dus een link aan kunnen klikken en de file kunnen downloaden.
verder heb ik de downloadpagina met het volgende script:
------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>download</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$filename = $_GET['file'];
$file-extension = substr( $filename,-3 );
if( $filename == "" )
{
echo "<html><title>Download mislukt</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
exit;
} elseif ( ! file_exists( $filename ) )
{
echo "<html><title>Download mislukt</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
exit;
};
switch( $file-extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type: $ctype");
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win"))))
{
header( "Content-Disposition: filename=".basename($filename).";" );
} else {
header( "Content-Disposition: attachment; filename=".basename($filename).";" );
}
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------
Ik krijg dit niet werkende.
alleen zie ik in de code geen fout ??