Download di File con limite di velocità

[sourcecode language=”php”]
<?php
$velocita_download = 10.20;
$download_file = ‘download‐file.zip’;
$file_destinazione = ‘target‐file.zip’;
if(file_exists($download_file)){
/* headers */
header(‘Last‐Modified: ‘.gmdate(‘D, d M Y H:i:s’).’ GMT’);
header(‘Cache‐control: private’);
header(‘Content‐Type: application/octet‐stream’);
header(‘Content‐Length: ‘.filesize($download_file));
header(‘Content‐Disposition: filename=’.$file_destinazione);
/* flush content */
flush();
/* open file */
$fh = @fopen($download_file, ‘r’);
while(!feof($fh)){
/* send only current part of the file to browser */
print fread($fh, round($velocita_download * 1024));
/* flush the content to the browser */
flush();
/* sleep for 1 sec */
sleep(1);
}
/* close file */
@fclose($fh);
}else{
die(‘Errore : il file ‘.$download_file.’ non esiste!’);
}
?>
[/sourcecode]

Potrebbero interessarti anche...

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *