Jump to content

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  ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.