PHP Classes

uncentralizedDownloader: Manage downloading of files from multiple servers

Recommend this page to a friend!
  Info   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 45%Total: 767 All time: 4,406 This week: 488Up
Version License PHP version Categories
ud 0.1GNU General Publi...4.0HTTP, Files and Folders


This package can be used to manage the download of files from one or more servers.

It can serve files for download. The files can be retrieved optionally from external servers according to configuration definitions file. The configuration file can be replicated to other files.

The download manager class can check the referer URL to prevent hot linking. The download URL are changed over time to make hot linking even more difficult.

Innovation Award
PHP Programming Innovation award winner
August 2007

Prize: One book of choice by O'Reilly
Many sites serve files for download to their users. When a site needs to serve many files for download, often it is necessary to distribute the download jobs between multiple servers.

This class implements an elegant solution that takes care of important details like being able to control from the main site server which users can download the files, hotlink prevention, replication of download configuration files, etc..

Manuel Lemos
Picture of Rémy Sanchez
Name: Rémy Sanchez <contact>
Classes: 4 packages by
Country: France France
Age: 34
All time rank: 949 in France France
Week rank: 18 Up1 in France France Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Uncentralized Downloader ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ by Rémy Sanchez ~~~~~~~ ~~ INTRODUCTION ~~ My website offers HTTP downloads to the users on a free host ( then I was pretty limited in the server features I could use. Moreover, I had to create several accounts because one was too small. But with time I faced several problems * Accounts randomly goes offline for several hours with no reasons * Some sites were hotlinking (they proposed my content to download as if it came from their site) The solution for the first problem was the uncentrilized downloader : instead of putting a file on a lonely account, I put it in several accounts, so if an account goes offline the file is still availible. UD's role is to scan all the accounts to produce a valid download link. In order to solve the second problem, I first did kind of rewrite rule (but using 404 errors instead of rewrite_mode since my host do not have rewrite_mod), to a file that first checks if the referer is good (so it is not a hotlink), then sends the file. This solution was good because transparent, but the use of 404 errors made download impossible on some browsers that prefer to show their own 404 pages (and I could not change HTTP header to do as if it was a OK answer), and with time we discovered it is pretty instable. Thus we had to find another solution. The idea was to change the URL every hour so it is impossible to link that file because the URL is never the same. To do so, I put the files into a folder that UD renames every hours. Of course, the role of UD is to know what the folder name is and to generate an URL the user can use to download the file he asked. That solution is not fully efficient but prevent hotlinks made by "bad" webmasters (mostly blogs). ~~ FEATURES ~~ * Prevent bad referers to download * Repartition of load on several severs * Central configuration file auto-dispatched on slave servers * Pages and messages customizable ~~ COMPONENTS ~~ # dirname.php That file contain the name of the files directory and the time it was changed. # dl.php It starts udManger. This file is the "user inteface" # ud_config.class.php Contain the configuration variable and the function that fetch the configuration # ud_fs_interact.class.php The functions in udFsInteract are the exlusive functions used by udManager to interact with the file system. It may allow to create virtual file systems (like files stored in the database) # ud_manager.class.php The main component of UD. It includes and loads the other components, and starts the download process. # ud_talk.class.php That class is used to talk between different servers. ~~ INSTALLATION ~~ You must have at least 1 server to install UD. Between all your servers you must chose a master, the other servers will be the slaves. The master distributes the configuration to the slaves. That allows you to change the configuration of your servers very fast. This can be useful when, by example, a new server comes online. You just have to add its URL in the master's config, and then it will be automaticaly propagated. The disavantage of that is that if your master server goes offline, your whole system is down, so chose your master carefully, or you can set all your servers as masters (but in that case you lose advantages of auto-propagated configuration) o) Master setup To set the master server up, you must upload the files into your server. Now you must configure the server. In that purpose, edit ud_config.class.php file and change the variables as you wish (each var come with a complete comment about its use and effects). $_mode MUST be set to UD_CONFIG_MODE_MASTER. Files to be uploaded - dirname.php (server must be able to read/write it) - dl.php - ud_config.class.php - ud_fs_interact.class.php - ud_manager.php - ud_talk.php - files (it is a directory that will be renamed by UD + server must be able to read/write it) o) Slaves setup The process is the same that for master, excepted that most of the configuration options are downloaded from the master, so you do not need to set them all. The comments in ud_config.class.php will tell you what variables will be downloaded from the master. $_mode MUST be set to UD_CONFIG_MODE_SLAVE. o) Uploading files There should be a directory named "files" in the files you uploaded. It is the directory in witch you can put the files. UD will rename it on its first launch. o) Make links Now you can make links. If your dl.php file URL is, and you want to download the file myfile.txt, then your download link will be Then dl.php will ask all the servers you have put in your configuration and then will show to the user a valid download link to one of the servers that have the file (or to none of the servers if the file cannot be found). ~~ LICENCE ~~ uncentralizedDownloader is licensed under GPL v2 (see GPL file).

  Files folder image Files  
File Role Description
Files folder imagefiles (1 file)
Files folder imagepages (5 files)
Accessible without login Plain text file dirname.php Appl. Contains the name of the downloadable files directory
Accessible without login Plain text file dl.php Appl. The file that creates an instance of udManager
Accessible without login Plain text file GPL Lic. The licence
Accessible without login Plain text file README Doc. The documentation
Plain text file ud_config.class.php Class udConfig class, fetches the configuration
Plain text file ud_fs_interact.class.php Class udFsInteract, the class to interact with the file system
Plain text file ud_mananger.class.php Class udManager, the main class
Plain text file ud_talk.class.php Class udTalk, the class to talk between servers

  Files folder image Files  /  files  
File Role Description
  Accessible without login Plain text file gpl.txt Data A sample file to be downloaded

  Files folder image Files  /  pages  
File Role Description
  Accessible without login Plain text file 200.php Appl. OK page template
  Accessible without login Plain text file 403.php Appl. Not authorized page template
  Accessible without login Plain text file 404.php Appl. Template file for Not Found error.
  Accessible without login Plain text file default.php Appl. When nothing to download, this page is shown
  Accessible without login Plain text file model.php Appl. The global template

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:4,406
This week:488Up
 User Ratings  
 All time