Created
December 21, 2022 14:28
-
-
Save emrahoruc/20d4e65f4cc5df0d99a277f6ac4739c0 to your computer and use it in GitHub Desktop.
Limit download speed using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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