Basierend auf meinem letzten Thread habe ich folgende WebSite entwickelt. Das Dumme daran ist, dass diese WebSite den Download zwar durchführt; allerdings sind die runtergeladenen Dateien
- korrupt, sprich fehlerhaft
- wesentlich kleiner als die Originaldatei
- der Inhalt der Dateien enthält nur HTML-Code
PHP:
<?php
function makeDownload($file) {
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Length: " . filesize($file));
header("Content-Type: application/octet-stream;");
readfile($file);
}
?>
<?php
$filename1 = "Bomberman.zip";
$filename2 = "PrimSound.zip";
$filename3 = "Vokabeltrainer.zip";
$filename4 = "PuzzleGame.zip";
$dir = getcwd() . "/Applications/";
?>
<?php
// Prüfe ERST, ob das Formular schon gesendet wurde (= Ein Submitbutton gedrückt wurde)
if (!empty($_REQUEST["download1"])) {
if (file_exists($dir . $filename1)) {
makeDownload($filename1);
} else {
echo("<center><h3>Datei nicht existent</h3></center>");
}
}
if (!empty($_REQUEST["download2"])) {
if (file_exists($dir . $filename2)) {
makeDownload($filename2);
} else {
echo("<center><h3>Datei nicht existent</h3></center>");
}
}
if (!empty($_REQUEST["download3"])) {
if (file_exists($dir . $filename3)) {
makeDownload($filename3);
} else {
echo("<center><h3>Datei nicht existent</h3></center>");
}
}
if (!empty($_REQUEST["download4"])) {
if (file_exists($dir . $filename4)) {
makeDownload($filename4);
} else {
echo("<center><h3>Datei nicht existent</h3></center>");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login Done</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div class="jumbotron">
<div class = "container">
<div class="row">
<div class="page-header">
<h2>Downloadbereich <small>Laden Sie meine Applikationen runter.... </small></h2>
</div>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-success progress-bar-striped active" style="width: 33%">
</div>
<div class="progress-bar progress-bar-warning progress-bar-striped active" style="width: 33%">
</div>
<div class="progress-bar progress-bar-danger progress-bar-striped active" style="width: 33%">
</div>
</div>
<div class="well">
<div class="panel panel-default">
<div class="panel-body">
<div class="alert alert-info" role="alert">Pushen Sie auf einen der Downloadbuttons, um die entsprechende Applikation runterzuladen</div>
</div>
<form action="<?= $_SERVER['SCRIPT_NAME']; ?>" method="post" >
<button onclick="Reload()">Reload Page</button>
<div class="panel-footer">
<div class="table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<th>Rubrik</th>
<th>Applikation</th>
<th>Programmiersprache</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<tr>
<td>Spiel</td>
<td>2D Shooter Jump'n Run</td>
<td>VB.NET</td>
<td><input type="submit" name="download1" class="btn btn-info btn-sm" value="<?= $filename1; ?>"></td>
</tr>
<tr>
<td>Mathematik</td>
<td>Primzahlen musikalisch eruieren</td>
<td>C#</td>
<td><input type="submit" name="download2" class="btn btn-info btn-sm" value="<?= $filename2; ?>"></td>
</tr>
<tr>
<td>Sprachen</td>
<td>Vokabeltrainer</td>
<td>C#</td>
<td><input type="submit" name="download3" class="btn btn-info btn-sm" value="<?= $filename3; ?>"></td>
</tr>
<tr>
<td>Logik</td>
<td>Puzzle zusammen setzen</td>
<td>DarkBasic</td>
<td><input type="submit" name="download4" class="btn btn-info btn-sm" value="<?= $filename4; ?>"></td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
</div>
<script>
function Reload() {
location.reload();
}
</script>
</body>
</html>