Nabend zusammen
Ich biete auf meiner Webseite eine Preisliste zum download an, das funktioniert auch wunderbar nur wenn ich die Datei dann öffnen will, kommt eine Fehlermeldung vom Adobe Reader, dass die Datei Beschädigt ist. Es ist eine PDF datei.
Hier mal der Code von meinem downloadscript:
PHP-Code:
<?php
// $download sei der Bezeichner für die zu ladende Datei
// etwa:
$download = $_GET['download'];
// Dieses Verzeichnis liegt außerhalb des Document Root und
// ist nicht per URL erreichbar.
$basedir = "/home/httpd/vhosts/gestach.ch/subdomains/lukas/httpsdocs/downloads";
// Übersetzung von Download-Bezeichner in Dateinamen.
$filelist = array(
"file1" => "preise.pdf",
"file2" => "ritter dev.mov",
"file3" => "datei1.zip",
"file4" => "nichtklicken.html"
);
// Einbruchsversuch abfangen.
if (!isset($filelist[$download]))
die("Datei $download nicht vorhanden.");
// Vertrauenswürdigen Dateinamen basteln.
$filename = sprintf("%s/%s", $basedir, $filelist[$download]);
// Passenden Datentyp erzeugen.
$tmp = explode(".", $filelist[$download]);
if ($tmp[1] == 'exe') $mimetype = "application/x-msdownload";
else if ($tmp[1] == 'zip') $mimetype = "application/zip";
else if ($tmp[1] == 'txt') $mimetype = "text/plain";
else if ($tmp[1] == 'gz') $mimetype = "application/gzip";
else if ($tmp[1] == 'xls') $mimetype = "application/msexcel";
else if ($tmp[1] == 'doc') $mimetype = "application/msword";
else if ($tmp[1] == 'gif') $mimetype = "image/gif";
else if ($tmp[1] == 'jpeg') $mimetype = "image/jpeg";
else if ($tmp[1] == 'jpg') $mimetype = "image/jpeg";
else if ($tmp[1] == 'pdf') $mimetype = "application/pdf";
else if ($tmp[1] == 'mp3') $mimetype = "audio/mpeg";
else if ($tmp[1] == 'mp4') $mimetype = "video/mpeg";
else if ($tmp[1] == 'rtf') $mimetype = "application/rtf";
else if ($tmp[1] == 'mid') $mimetype = "audio/mid";
else if ($tmp[1] == 'wav') $mimetype = "audio/x-wav";
else if ($tmp[1] == 'rar') $mimetype = "compressed/rar; application/x-rar-compressed";
header("Content-Type: $mimetype");
// Passenden Dateinamen im Download-Requester vorgeben,
// z. B. den Original-Dateinamen
$save_as_name = basename($filelist[$download]);
header("Content-Disposition: attachment; filename=\"$save_as_name\"");
// Datei ausgeben.
readfile($filename);
?>
Was mache ich falsch oder was ist falsch an diesem Code?
Danke schon im Voraus dür die Antworten
Hier ist der Link für den download der Datei preise.pdf:
http://lukas.gestach.ch/downloads/do...download=file1
Gruss Lukas