www.KevinBurkholder.com

Getting Work Done Through People

Getting People Done Through Work

www.KevinBurkholder.com
Strengths Based Performance Management
EarthAsylum Consulting
The EarthAsylum Leadership Circle
The EarthAsylum Fusion Network
Tuesday, November 25, 2008

eac_download.class.php PHP Download Manager

eac_download.class.php

Source Code

Download eac_download.zip

Interested in using this software in your project? Contact Kevin at KBurkholder@EarthAsylum.com
Creative Commons License This work is licensed under the Creative Commons GNU-LGPL License.
Licensing & Registration
 
Donations are greatly appreciated and help fund further development and maintain the LGPL licensing.

Overview

eac_download.class is both a secure wrapper for PEAR HTTP/Download.php and a logger of download activity. It validates download requests to ensure only valid requests are processed and it logs requests, successful downloads and failed downloads to SQLite database files.

 

Included in the archive is a simple reporting script that shows a summary of files downloaded and the detail of successfull and failed download attempts.

 

Options passed to the constructor (and default values):

$options['dbpath']       =  (isset($_SERVER['DOCUMENT_ETC']))
                                 ? 
$_SERVER['DOCUMENT_ETC']
                                 : 
$_SERVER['DOCUMENT_ROOT'];
$options['filetypes']    = array();
$options['session']      = true;
$options['referral']     = true;
$options['blacklist']    = true;
$options['includepath']  = true;
 

dbpath is the directory path were the log files are to be stored. Log file names are 'download_yyyymm.log'.

filetypes is an array of allowable file extensions:
$options['filetypes'] = array('zip','pdf'); 

session, when true, means that there must be an active session. This prevents direct downloads via outside links. This would most likely block crawlers from downloading as well as anyone with cookies disabled (id sessions are managed via cookies).

referral, when true, means that the HTTP_REFERER variable must contain the local domain name. This would also block direct links and outside links as well as anyone stripping the HTTP_REFERER variable.

blacklist, when true, uses PEAR Net/DNSBL.php to do a DNS lookup of the remote IP address at sbl-xbl.spamhaus.org to determine if the IP is listed as a spam/exploit source.

includepath means to search the PHP include path for the file.

Instantiation

include 'eac_download.class.php';
$dl = new download($options);
try {
    
$dl->start($file,$name,$content);
} catch (
Exception $e) {
    
// whatever you want to do with the error...
    
header("HTTP/1.1 403 Forbidden");
    die(
"<h3>403 Forbidden</h3>".$e->getMessage());
}
 

$file is the file path name to be downloaded. If the file is not found, we'll look in the
document root and, optionally, through the PHP include path.
$name is the optional name to download the file as - i.e. it can be downloaded with a different
name. If not used, the actual file name is used.
$content is an optional buffer containing the actual content of the file - i.e. via file_get_contents.
If used, $file is not needed but one of $file or $name is required to name the file content.

Getting download statistics for the current month:

include 'eac_download.class.php';
$dl = new download($options);
$dl->getLog($key);
 

$key is either the $file or $name used when downloading a file. getLog() returns an associative
array of the counts for the file.

array(
    
'dlName'       // the file name (path if dlLogType is file, else base name)
    
'dlLogType'    // either 'file' or 'name'
    
'dlAttempt'    // the number of attempted downloads
    
'dlSuccess'    // the number of successful downloads
    
'dlFailure'    // the number of failed downloads
    
'updated'      // the date/time of the last download attempt
);
 

Getting download statistics for all months:

include 'eac_download.class.php';
$dl = new download($options);
$dl->getAllLogs($key);
 

$key is either the $file or $name used when downloading a file. getLog() returns an associative
array of the counts for the file.

array(
    
'dlName'       // the file name (path if dlLogType is file, else base name)
    
'dlLogType'    // either 'file' or 'name'
    
'dlAttempt'    // the number of attempted downloads
    
'dlSuccess'    // the number of successful downloads
    
'dlFailure'    // the number of failed downloads
    
'updated'      // the date/time of the last download attempt
);
 

 

 Powered by  eac::Framework 

eac::Framework is a lightweight PHP & JavaScript framework for Web 2.0 Applications and E-Commerce systems.

For more information, visit http://www.KevinBurkholder.com/framework

eac::encryption, eac::session, eac::keychain, eac::dataobjects, eac::tracker, eac::sourcing, eac::authentication, eac::filter, eac::formgen, eac::caching, eac::mailer, eac::download, eac::error, eac::streams and more.