Skip to content

Instantly share code, notes, and snippets.

@emrahoruc
Created December 21, 2022 14:28
Show Gist options
  • Save emrahoruc/20d4e65f4cc5df0d99a277f6ac4739c0 to your computer and use it in GitHub Desktop.
Save emrahoruc/20d4e65f4cc5df0d99a277f6ac4739c0 to your computer and use it in GitHub Desktop.
Limit download speed using PHP
<?php
// source https://stackoverflow.com/a/12245044/3254912
set_time_limit(0);
$file = array();
$file['name'] = 'image.JPG';
$file['size'] = filesize($file['name']);
header('Content-Type: image/jpeg');
header('Content-Description: file transfer');
header('Content-Disposition: attachment; filename="' . $file['name'] . '"');
header('Content-Length: '. $file['size']);
$open = fopen($file['name'], 'rb');
while( !feof($open) ){
echo fread($open, 256);
usleep(750);
}
fclose($open);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment