Search
 
SCRIPT & CODE EXAMPLE
 

PHP

download speed limit php

<?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 :: difference betwen include and indlude once 
Php :: limit offset array php 
Php :: insert php variable css 
Php :: last 6 digits of string laravel 
Php :: wp display custom fields 
Php :: run raw sql with doctrine manager 
Php :: fore install debian 10 php 7.3 
Php :: add column in table laravel 
Php :: convert dd/mm/yyyy to yyyy-mm-dd in mysql php 
Php :: check if all values in array are equal php 
Php :: appending txt file from php 
Php :: make controller laravel 8 with resource 
Php :: how to create compomemt in laravel livewire 
Php :: Laravel Session using Global Session php function 
Php :: laravel display old value in form 
Php :: create a user using tinker 
Php :: include and require in php 
Php :: php array common element 
Php :: mac os change the php verison 
Php :: Numbers Formater Decimal & Thousand Separator PHP 
Php :: Artisan::call for all catch clear in laravel 
Php :: php while loop of alphabet 
Php :: open php tag 
Php :: get order details by id woocommerce 
Php :: show display error php 
Php :: php superglobal 
Php :: undefined method JeroenNotenLaravelAdminLteHelpersMenuItemHelper::isSearchBar() 
Php :: how validate data if is exist must not be empty in laravel 
Php :: add foreign key column laravel 5.8 
Php :: delete method laravel 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =