Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php download rate limit

<?php

$file_to_download = '1.mp3';
$client_file = '1.mp3';

$download_rate = 10; // 200Kb/s

$f = null;

try {
	if (!file_exists($file_to_download)) {
		throw new Exception('File ' . $file_to_download . ' does not exist');
	}

	if (!is_file($file_to_download)) {
		throw new Exception('File ' . $file_to_download . ' is not valid');
	}

	header('Cache-control: private');
	header('Content-Type: application/octet-stream');
	header('Content-Length: ' . filesize($file_to_download));
	header('Content-Disposition: filename=' . $client_file);

	// flush the content to the web browser
	flush();

	$f = fopen($file_to_download, 'r');

	while (!feof($f)) {
		// send the file part to the web browser
		print fread($f, round($download_rate * 1024));

		// flush the content to the web browser
		flush();

		// sleep one second
		sleep(1);
	}
} catch (Throwable $e) {
	echo $e->getMessage();
} finally {
	if ($f) {
		fclose($f);
	}
}
Comment

PREVIOUS NEXT
Code Example
Php :: codeigniter query builder order by 
Php :: laravel mongodb delete 
Php :: limit offset array php 
Php :: laravel make model and controller 
Php :: wordpress get user by id 
Php :: if any error in blade laravel 
Php :: wp-admin redirecting to the https wordpress 
Php :: PHP CSV File Export Using fputcsv() 
Php :: change php version using htaccess 
Php :: php put print_r into variable 
Php :: how to write for loop in laravel blade 
Php :: carbon finer 
Php :: grouping routes in laravel 
Php :: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.9.1/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223 mac 
Php :: woocommerce change "Billing Details" text 
Php :: how to create a get route in Laravel 
Php :: laravel cmd command to watch logs 
Php :: php string replace regex 
Php :: php install xdebug mac 
Php :: php generate random string 
Php :: why laravel site loading only 
Php :: php foreach mysql result 
Php :: Laravel Auth Redirect based on role 
Php :: If a String Contains a Specific Word in PHP 
Php :: laravel date set timezone 
Php :: try catch in laravel 
Php :: Laravel validating birthdate by 13 years old 
Php :: laravel get url path 
Php :: how to get the list of available timezones in php 
Php :: phpmyadmin first login 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =