Skip to content

Instantly share code, notes, and snippets.

@SilentKernel
Created February 11, 2018 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SilentKernel/4fa739137cc4f6356fc07b3778da747f to your computer and use it in GitHub Desktop.
Save SilentKernel/4fa739137cc4f6356fc07b3778da747f to your computer and use it in GitHub Desktop.
<?php
// On recupere la vitesse, renvoie 0 si du texte est entré ici
$speed = intval($_GET["speed"]);
// Le nom du fichier (sur le disque et envoyer au navigateur)
$filename = "ubuntu-14.04.3-desktop-amd64.iso";
/* On évite les valeurs hors sujet pour la vitesse (et on met max 1 mega octet par seconde) */
if ($speed > 0 && $speed <= 1000) {
// Convertie octet en kilo octet
$speed *= 1000;
// Type du fichier, Nginx ne le renvoie pas automatiquement
header("Content-type: application/octet-stream");
/* Le nom du fichier sinon le navigateur telechargerait un "download.php" de 1 GO */
header("Content-disposition: attachment; filename=\"" . $filename . "\"");
// Ou se trouve le fichier à télécharger, voir la config NGINX
header("X-Accel-Redirect: /ISO/" . $filename);
// On limite le téléchargement à la vitesse demandé.
header("X-Accel-Limit-Rate: " . $speed);
} // Si $speed a une valeur hors sujet (0 ou du texte par exemple)
else {
echo "La vitesse demandé n'est pas bonne !";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment