steviez Posted July 3, 2007 Share Posted July 3, 2007 Hi, I run a file hosting site and would like to calculate the amount of bandwidth a file has used, all my file details are stored in a database (MYSQL) is there a way to do this in PHP? Thanks guys! Quote Link to comment Share on other sites More sharing options...
wcsoft Posted July 3, 2007 Share Posted July 3, 2007 Do you track the number of times the file has been downloaded in the db as well? If so, then you could easily just multiple the number of downloads by the file size. Quote Link to comment Share on other sites More sharing options...
steviez Posted July 3, 2007 Author Share Posted July 3, 2007 Yes is do, Im a complete nOOoob to PHP, please could you help me on this? how do i do this? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 3, 2007 Share Posted July 3, 2007 <?php $totalbytes = $filesize * $num_downloads; echo $totalbytes . " bytes<Br />" . ($totalbytes/1000) . " MB<br />" . ($totalbytes/1000000) . "GB"; ?> Fun stuff. Quote Link to comment Share on other sites More sharing options...
TreeNode Posted July 3, 2007 Share Posted July 3, 2007 You will not get the precise bandwidth usage for a file if all you do is multiply the times downloaded by the size of the file. This does not take into account the people who canceled the download. If you don't know PHP, you could always look into server logs, possibly even download another free software program that could parse out that information for you. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 3, 2007 Share Posted July 3, 2007 You will not get the precise bandwidth usage for a file if all you do is multiply the times downloaded by the size of the file. This does not take into account the people who canceled the download. If you don't know PHP, you could always look into server logs, possibly even download another free software program that could parse out that information for you. That is true, but it will give an estimate of usage, which will be shot high. I would rather have a higher estimate than a lower. Quote Link to comment Share on other sites More sharing options...
steviez Posted July 3, 2007 Author Share Posted July 3, 2007 What i want to do is tell each user how much BW they have used, then if possable have like a percentage bar? Is this very hard to do? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 3, 2007 Share Posted July 3, 2007 What i want to do is tell each user how much BW they have used, then if possable have like a percentage bar? Is this very hard to do? Anything worth doing is hard to do. I am sure you can find something already done on google. Quote Link to comment Share on other sites More sharing options...
steviez Posted July 3, 2007 Author Share Posted July 3, 2007 i have tried, now unless im typing in the wrong thing i cant find anything. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 3, 2007 Share Posted July 3, 2007 The percentage bar can easily be done in CSS or with www.php.net/image functions using www.php.net/gd the GD2 Library. The bandwidth per user is pretty easy to calculate you just pull the download logs for each user and tally up the bytes for the file for the number of times they downloaded it. http://www.codewalkers.com/c/a/File-Manipulation-Code/Bandwidth-Control-with-pure-PHP/ Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 3, 2007 Share Posted July 3, 2007 @ steviez - I'd say you now have everything you need to begin coding the script you want. When you have some code, please post it and identify any problems you're having with it. Remember this is free help - members helping you, not members writing scripts for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.