Jump to content

Is this possable with PHP?


steviez

Recommended Posts

Hi,

 

I am trying to develop a file hosting script for my site and need the following feature but need to know if it can be done with PHP?

 

I need to limit the speed of downloads for non premium users and only let them download so much in a certen period. Can this be done and if so can anyone point me in the right direction?

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/83735-is-this-possable-with-php/
Share on other sites

<?php
$file = "test.mp3"; // file to be send to the client
$speed = 8.5; // 8,5 kb/s download rate limit
if(file_exists($file) && is_file($file)) {
header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: filename=$file" . "%20");
flush();
$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024));
flush();
sleep(1);
}
fclose ($fd);
}
?> 

Google is amazing  ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.