• Join/Login
  • Business Software
  • Open Source Software
  • For Vendors
  • Blog
  • About
  • More
    • Articles
    • Create
    • SourceForge Podcast
    • Site Documentation
    • Subscribe to our Newsletter
    • Support Request
SourceForge logo
For Vendors Help Create Join Login
SourceForge logo
Business Software
Open Source Software
SourceForge Podcast
Resources
  • Articles
  • Case Studies
  • Blog
Menu
  • Help
  • Create
  • Join
  • Login
  • Home
  • Browse
  • Link - Php download script
  • Wiki
Link - Php download script

Link - Php download script Wiki

Php file download serving script

Status: Beta
Brought to you by: k00lman
  • Summary
  • Files
  • Reviews
  • Support
  • Code
  • Donate
  • Wiki
Menu ▾ ▴
  • Wiki Home
  • Browse Pages
  • Browse Labels
  • Formatting Help

Home

Eper Kalman

Link - file serving script

Link is a small file serving script in early beta state with random links, resume capability, configurable download speed, logging system and connections number control released under GNU Lesser General Public License. Requires Php and MySQL/MariaDB web server with PDO and MBString support in order to store and serve random generated download links.

The script relies on Php connection handling and flush functions therefore some servers (like IIS with ResponseBufferLimit) may need additional tuning for enabled connection counting functionality.

Usage

Before installing the database the credentials have to be defined in file cfg/database.ini. Also an existing database have to be defined. After the tables needed can be installed with commands:

<?php

    include 'app/link.class.php';

    $l = new Link();

    if (! $l->isDatabaseReady()) exit('No database connection');

    $l ->_DataBase->install();   # Returns TRUE on success.

?>

The ip address connected with generated link and download may be set by parameter below if is not the request ip address used by default.

<?php

    $l->_ClientIpAddress = '::1';

?>

The generated link can be locked (will be valid) to determined or defined ip address via parameter below. This parameter have to be set before link generation and can be different for each link. By default no lock is set.

<?php

    $l->_IpAddressLockedLink = TRUE;

?>

Every download gets first a randomly generated ID.

<?php

    include 'app/link.class.php';

    $l = new Link();

    $id = $l->generateForFile('/path/file.txt');

?>    

Downloads are started with defined ID.

<?php

    include 'app/link.class.php';

    $l = new Link();

    $l->setDownloadID($id);

    $l->serveCurrentId();   /* Function returns codes:  1 - success
                                                        2 - file not found
                                                        3 - request denied 
                                                        4 - error or connection aborted
                                                        5 - expired link */

?>

Database connection functionality can be verified with

<?php

    if (! $l->isDatabaseReady()) exit('No database connection');

?>

The download avialabity can be checked with method isAllowedDownload():

<?php

    if ($l->isAllowedDownload()) $l->serveCurrentId();

?>

Expired links can be detected with function isExpiredLink() as

<?php

    if ( (! $l->isAllowedDownload()) && $l->isExpiredLink() ) exit('Expired');

?>

Function setDownloadID() have to be followed shortly with serveCurrentId() because of database row locking, do not make time consuming operations between them if is possible.

User configurable settings

Download speed in kilobytes. Default 1024 kb/s .

<?php

    $l->_DownloadSpeedKb = 1024;

?>

Download link lifetime in minutes. Default 1440.

<?php

    $l->_LifetimeAllowed = 1440;   

?>

Allowed simultaneous connections number to link (can be different for each). Default 5.

<?php

    $l->_ConnectionsAllowed = 5;

?>

Disabling (by default enabled) maximum simultaneous connection number checking is possible via

<?php

    $l->_NoConnectionsLimit = TRUE;

?>

Enable logging into database or log file. Default FALSE. Possible values FALSE/DB/TXT.

<?php

    $l->_DownloadsLog = 'TXT';

?>

Log files directory in a case of file log

<?php

    $l->_logRootDirectory = 'writable_directory';

?>

Rejected requests logging is by default disabled because of possible large number of denied requestes created by download managers. Controlling this behavior is possible with

<?php

    $l->_RejectedRequestLog = FALSE;

?>

Encoding non Latin-1 characters to database (for storing the links). Default TRUE. Not necessary if database charset, collation and filenames encoding is synchronized (e.g. UTF-8).

<?php

    $l->_FilenamesEncoding = TRUE;

?>

By default the script will use internal encoding as filesystem encoding for storing filenames into database log if explicite is not defined with:

<?php

    $l->_FileSystemEncoding = FALSE; # (default FALSE, possible values UTF-8...)

?>

By default if file not found or some other error happends not found 404 header is send. This functionality can be disabled with

<?php

    $l->_SendNotFoundHeader = FALSE;

?>

By default in a case of rejected requestes 403 forbidden header is send. This funcionality also can be disabled by

<?php

    $l->_SendForbiddenHeader = FALSE;

?>

By deafult the script starts with a delay of 0.5s . This functionality can be controlled by

<?php

    $l->_DelayAtStart = 500000; 

?>

The value is defined in microseconds, 0 turns off delay.

The script by default resets download counters to 0 automatically after system restart. This behavior can be disabled with calling the main class with parameter FALSE as

<?php

    $l = new Link(FALSE);

?>

and the counter can be reseted manually with

<?php

    $l->resetDownloadCounters();

?>

If for some reason you need other language for reports it have to be defined before including the main Link class.

<?php

    define('D_LANGUAGE', 'other'); # (file extension of language file lang/language.other)
    include 'app/link.class.php';

?>

In a case of configuration changes in ./conf/database.ini reset the cache files and load the new configuration with:

<?php

    $l->configurationReset(); 

?>

Directories ./tmp and ./log have to be writable for web user in order to use the script.

This script is distributed in the hope that it will be useful, feel free to include it in your (open sourced or commercial) projects.

According to LGPL License the script is provided "AS IS", without warranty of any kind.

You can contact me related to script (bugs or suggestions) via mail kami.eper@gmail.com .

Thanks in advance and best regards

Project Members:
  • Eper Kalman (admin)


SourceForge
  • Create a Project
  • Open Source Software
  • Business Software
  • Top Downloaded Projects
Company
  • About
  • Team
  • SourceForge Headquarters
    1320 Columbia Street Suite 310
    San Diego, CA 92101
    +1 (858) 422-6466
Resources
  • Support
  • Site Documentation
  • Site Status
  • SourceForge Reviews
SourceForge logo
© 2025 Slashdot Media. All Rights Reserved.
Terms Privacy Opt Out Advertise
×