Skip to content

Instantly share code, notes, and snippets.

@AdriDevelopsThings
Created May 30, 2021 13:24
Show Gist options
  • Save AdriDevelopsThings/3f28a0a09460d598ed0d2e396f49cc32 to your computer and use it in GitHub Desktop.
Save AdriDevelopsThings/3f28a0a09460d598ed0d2e396f49cc32 to your computer and use it in GitHub Desktop.
unlimited-download.php downloads 'bilder.zip' with infinite size.
<?php
// Consts
$UNLIMITED_DOWNLOAD_OUTPUT = "unlimited_download_output";
$BUFFER = 1024 * 1024;
$WRITE_BUFFER = 64 * 1024 * 1024;
function writeInformation ($size) {
$data = "Headers:\n";
foreach($_SERVER as $key => $value) {
if (substr($key, 0, 5) <> 'HTTP_' && gettype($value) == "string") {
$data = $data . $key . ": " . $value . "\n";
}
}
$data = $data . "\nSize:\n" . $size;
$out = file_put_contents("unlimited_download_output" . DIRECTORY_SEPARATOR . $_SERVER['REMOTE_ADDR'] . ".txt", $data);
if ($out === false) {
die("Log function failed: status false.");
}
}
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=bilder.zip');
if (!is_dir($UNLIMITED_DOWNLOAD_OUTPUT)) {
mkdir($UNLIMITED_DOWNLOAD_OUTPUT);
}
$i = 0;
while(true) {
echo random_bytes($BUFFER);
$i += $BUFFER;
if ($i % $WRITE_BUFFER == 0) {
writeInformation($i);
}
flush();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment