Hallo Leute,
folgender an sich simpler Code soll eine jeweilige Datei downloaden. Das funktioniert soweit auch, allerdings kann ich die Datei nicht entpacken; sie ist beschädigt(Das Original hingegen ist unbeschädigt). Weiß jemand Rat?
folgender an sich simpler Code soll eine jeweilige Datei downloaden. Das funktioniert soweit auch, allerdings kann ich die Datei nicht entpacken; sie ist beschädigt(Das Original hingegen ist unbeschädigt). Weiß jemand Rat?
PHP:
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Upload</title>
</head>
<body>
<?php
$filename1 = "Programmierung.zip";
$filename2 = "VBA_for_Excel.zip";
$dir = getcwd() . "/";
$type = 'application/zip';
?>
<form action="download.php" name="formular" id="formular" method="post" >
<p>Downloadbuttons:</p>
<input type=submit name="download1" id="betreff" value="<?php echo $filename1 . " Downloaden"; ?>"><br>
<input type=submit name="download2" id="betreff" value="<?php echo $filename2 . " Downloaden"; ?>"><br>
</form>
<?php
if (!empty($_REQUEST["download1"])) {
if (file_exists($dir . $filename1)) {
makeDownload($filename1, $dir, $type);
} else {
echo"<h3>Datei nicht existent</h3>";
}
}
if (!empty($_REQUEST["download2"])) {
if (file_exists($dir . $filename2)) {
makeDownload($filename2, $dir, $type);
} else {
echo"<h3>Datei nicht existent</h3>";
}
}
?>
</body>
</html>
<?php
function makeDownload($file, $dir, $type) {
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=\"$file\"");
//readfile($dir . $file);
}
?>
Zuletzt bearbeitet: