just code

[PHP] How-to Configure Digital Download

| Comments

Hi, finally I got a bit of time to write this guide (in two parts) to configure -this page- and use my PHP class named Digital Download (for end users). There are several variables because there are many aspetcs to configure, but it is not that difficult ;)

I assume that you have uploaded the digitalDownload directory in the root of your website (eg.: but how you will can see, is not important.

Configuration of DigitalDownload

All the configuration are in the file


Follow this symple steps:

1) Definition of paths.

If you don’t understand or you don’t need to particular configuration don’t touch the follow lines.

define('DD_DIR', __DIR__.'/');

// If you can, put the download directory outside of a public directory

define('DD_PATH', DD_DIR.'download/');

define('DD_L_PATH', DD_DIR.'labels/');

2) Basic configuration:

protected $host = ''; // change this with your domain name

Your site address (important! Pay attention that is exactly your address how you can look in the address bar of your browser but without the initial ‘http://’ and the final slash ‘/’ )

public $install  = 1; // Set to 1 to reinstall and regenerate the codes, 0 otherwise

Set to 1 to install (or reinstall) the codes. Old codes will be overwritten!

public $downloadsAllowed = 1; // Set to 1 to allow downloads, 0 otherwise

Set to 1 to permit the downloads with the generated codes after the installation. If you set this value to 1 but the $install value is also to 1 the script does not allow the download.

public $createLabel = 1; // Create labels at the end of installation

Set to 1 to create the labels at the end of installation.

public $createPdf = 0; // Create a pdf with the labels at the end of installation

Set to 1 to create a pdf with the labels at the end of installation. You need to set to 1 $createLabel to generate the pdf. All the labels will be included in to pdf to print it.

public $pdfOrientation = 'L'; // P or L

Orientation of PDF’s pages: P = ‘Vertical page’, L = ‘Landscape’. Depend on dimension of your labels choose the ‘rigth’ orientation.

public $pdfDpi = 300;

Print resolution. Don’t touch.

public $regeneratePdf = 0; // During installation regenerate ONLY the pdf, not the labels

You can make several test of PDF generation with labels. Set $install to 1 and 1 this value to use the same labels to define the layout of PDF (orientation, margin, ecc).

public $downloadPdf = 0; // At the end of installation, or regeneration of pdf: 0 = download directly the pdf, 1 = save pdf in labels directory with name 'labels.pdf'

Set to 0 to download directly the PDF after the generation or 1 to save the document inside the ‘labels directory’ ($labelsDirectory).

public $pdfMarginX = 10; // Left margin

public $pdfMarginY = 10; // Top margin

Left margin and top margin of generated PDF. (This is the starting point where the images will be placed).

3) Paths and files configuration

public $backgroundImagePath = 'labels/'; // image path with trailing slash

Path when you put the background of the labels relative to installation directory. Your path is ‘/path/www/digitalDownload/‘? Ok, $backgroundImagePath will be ‘/path/www/digitalDownload/labels’. Print to the screen ‘DD_DIR’ if you do not know your path.

public $stringColorRed = 0;

public $stringColorGreen = 0;

public $stringColorBlue = 0;

RGB codes of the Code string ($stringToWrite) will be printend over the background image label ($backgroundFileName). If you don’t know the RGB values of your color, visit this page

public $fontSize = 30;

Font size of $stringToWrite

public $stringAngle = 0;

The angle at which it will print the message ( 0 = Horizontal, 90 = Vertical, etc…)

public $startX = 380;

public $startY = 374;

The start point will be placed the Code string above the background. Make several tests :)

public $fontName = 'georgia_italic.ttf'; // other free fonts here:

The font name used to print the Code string.

public $stringToWrite = ''; // UTF-8 encoded string

All values will be replaced with the Code string

public $fullPath= DD_DIR;

public $downloadDirectory = DD_PATH;

public $labelsDirectory = DD_L_PATH;

Paths of installation. Don’t touch if you don’t understand.

public $backgroundFileName = 'digitaldownload.gif';

The filename of Labels background. Put the file in the $labelsDirectory.

public $fileToDownload = 'ajax-loader.gif'; // File to download listed in the 'download' directory

The filename to download after the code verification. Put the file in the $downloadDirectory.

4) Code settings

public $codeLenght = 10; // how many long are the code string?

Lenght of the code. Pay attention: a code too long with a big $fontSize will be print out of the label.

public $codeNum = 2; // how many codes?

How many unic codes will be generated?

public $limitNumDownload = 5; // how many time a code is valid? 0 = unlimited

How many times a code is valid to permit the download? 1 = 1 code for 1 download, etc… 0 = unlimited: 1 code for unlimited downloads.

public $limitByHour = 2; // hour numbers from first use to expire 0 = unlimited

How many hours a code is valid after the first download with the same code? 1 = first download at the 2:00PM. The code still valid until the 3:00PM. You can combine $limitNumDownload with $limitByHour at your desire. For example you can permit one download per code for one hour, or twelve download per code without time limits (at thirteenth use of code will be displayed an error).

5) Database settings

DigitalDownloads need a MySql database to work (but you can modify PDO’s statements in the ‘createDbConnection’ method) and a user that have access to manage tables in the database. If you have a problem contact your administrator.

const DD_DB_HOST = 'host';

Database Host (basically localhost).

const DD_DB_USER = 'user';

Database user.

const DD_DB_PASS =  'pass';

Password of database user.

const DD_DB_DATABASE = 'database';

The existent database to use.

const DD_DB_CODES_TABLE = 'DD_codes';

Name of the table will be put the generated codes

const DD_DB_LOG_TABLE = 'DD_downloads_logger';

Name of the table with the logs of codes utilizations.

6) Installation Output config

public $eof  = "<br/>";

public $titleOpen   = "<h3>";

public $titleClose = "</h3>";

Simply the title dimension and the code to new line during installation. Don’t touch if you don’t need to stylize the output of installation.

Ok, you have configurated the system, now, test and use it!