Current location: Hot Scripts Forums » Programming Languages » PHP » On development: Download manager


On development: Download manager

Reply
  #1 (permalink)  
Old 10-09-04, 05:01 AM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
On development: Download manager

I'm building a package for managing download action. The package will be equipped with ability to limit download bandwith on individual, daily, and monthly basis.
Below, I will show the code snippet for the download class, which is the main part of the download manager. If any of you is interested in this package, you can support me by giving donation, joining the developer team, or providing hosting.

Here is the code snippet
PHP Code:

<?php


/**************************************************************\
 *    File    :download-class.php                               *
 *  Version :0.1a                                             *
 *  Desc.   :A class for bandwidth managing in server side    *
 *           download                                         *
 *  Compat. :PHP4 > 4.1.0, UNIX                               *
 *  Author  :moron_moronovich [at] yahoo.com                  *
\**************************************************************/

class download {
    
/*private*/ var $delayTime 0;
    
/*private*/ var $fieldSep$crLf$myDateFormat;
    
/*private*/ var $logFileName,$logFileContent;
    
/*private*/ var $unixTime,$curDate,$curMonth,$curYear 0;
    
/*private*/ var $curMonthBw,$curDayBw,$curLogMonthSpentBw$curLogDaySpentBw$curLogDate,$curLogMonth,$curLogYear$todayLastSpentBw 0;
    
/*private*/ var $accRestBw//boolean
    /*private*/ 
var $todayDownload$indivDlLimit 0;
    
    
/*Access public
     *Contructor
     */
    
function download() {
        
session_start();        
        
error_reporting(0);
        
//Set up session name
        
if(isset($_SESSION['dlCount']) && preg_match('/[0-9]+/',$_SESSION['dlCount'])) {
            
$dlCount $_SESSION['dlCount'];
        }
        else {
            
$dlCount $_SESSION['dlCount'] = 0;
        }
        
$this->todayDownload $dlCount;
    }
    
    
/*Access private
     *return integer
     */
    
function getTime($delayTime) {
        
$now time() + $delayTime;
        
$this->delayTime delayTime;        
        return 
$now;
    }
        

    
/*Access Public
     *return void
     */
    
function setupLog ($logFileName,$fieldSeparator'#',$newLine "\r\n") {
        
$this->crLf $newLine;
        
$this->fieldSep = ($fieldSeparator == '/') ? '\/'$fieldSeparator;
        if(!
file_exists($logFileName)) {            
            
$this->message(0);
        }
        
$this->logFileName $logFileName;
        
$this->dateFormat $dateFormat;
        
$curTime getTime(0);
        
$this->unixTime $curTime;
        
$this->curDate date('d',$curTime);
        
$this->curMonth date('m',$curTime);
        
$this->curYear date('Y',$curTime);        
    }
    
    
/*Access Public
     *return void
     */
    
function setupBandwidth ($monthlyBandwith$accRest true) {
        
$this->curMonthBw $monthlyBandwith;
        
$this->accRestBw $accRest;
    }
    
    
/*Access Public
     *return int
     */
    
function individualDownloadLimit($dlLimit) {
        
$this->indivDlLimit $dlLimit;
    }
    
    
/*Access private
     *return void
     */
    
function readLogFile() {
        
$fp fopen($this->logFileName,'rb');
        if(!
$fp)
            
$this->message(1);
        
flock($fp,LOCK_SH);
        
$content fread($fp,filesize($this->logFileName);
        
flock($fp,LOCK_UN);        
        
fclose($fp);
        
$this->logFileContent $content;
    }
    
    
/*Access private
     *return void
     */
    
function fetchLogData () {
        if(
preg_match('/\(d{1,2})\/\(d{1,2})\/\(d{4})'.$this->fieldSeparator.'(\d+)'.$this->crLf.'$/',$content,$matches)) {
            
$this->curLogMonth $matches[1];
            
$this->curLogDate $matches[2];
            
$this->curLogYear $matches[3];
            
$this->curLogDaySpentBw $matches[4];
        }
        
$arrayDate explode($this->crLf$content);
        for(
$i=0$i<count($arrayDate); $i++) {
            if(
preg_match("/".$this->curMonth."\/\d{1,2}\/".$this->curYear.$this->fieldSep."(\d+)/",$arrayDate[$i]),$matches) {
                
$curLogMonthSpentBw += $matches[1];
            }
        }
        
$this->curLogMonthSpentBw $curLogMonthSpentBw;
                        ......
to be continued
Thanks for reading this thread.
__________________
just an ignorant noob with moronic solution...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Download manager mrtero Script Requests 1 10-17-04 07:10 AM
A small, basic download manager mdhall Script Requests 0 06-14-04 05:08 AM
PHP download... niceguyonline Script Requests 3 03-06-04 05:41 PM
image gallery and download manager weither_lang Script Requests 0 01-26-04 02:23 AM
Need download Manager script Dead Socket General HotScripts Site Discussion 4 07-22-03 03:37 AM


All times are GMT -5. The time now is 04:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.