File downlaods

Commands

dbr.download - Serve file(s) from the filesystem

Syntax

select 'dbr.download', ['dynamic' | null [, 'readfile' | 'x-sendfile' ]]

Explanation

The command enables secure serving of files from the filesystem.

Environment settings manage the configuration of this command. Files can be served using two methods: PHP's readfile and X-Sendfile. The default method is readfile. X-Sendfile allows myDBR to delegate file serving to the web server, thus conserving PHP resources. Configuring X-Sendfile requires setup on the web server. Files can be served with unique URLs for each user's session (dynamic) or unique to the user (static). The mandatory base directory sets the root directory for file serving.

The command allows overriding the default mode (static/dynamic) and method (readfile/x-sendfile).

The result set from this command generates download links. The first column specifies file paths relative to the base directory. The final column in the result set defines the HTML code used to display each link. HTML codes contain variables filled with column values. The predefined #url variable is replaced with the generated download URL. The HTML can be direct HTML or a myDBR template.

The dataset required for the command:

select path_to_a_file_or_files, optional_columns, html_or_template_to_be_shown;

The file download statistics are recorded into the mydbr_file_downloads-table.

Examples

Serving a Single File as a Sample Link and a Direct HTML Code

myDBR will replace the field #url variable with the generated URL. The example includes an additional variable (title).


select 'dbr.download';

select 'folder/file.pdf', 'A sample document' as 'title', '<a href="{#url}">{#title}</a>';

/* The HTML code could be coming from a template */

select 'dbr.download';

select 'folder/file.pdf', 'A sample document' as 'title', '#template_link';


Serving a Single File as a Sample Link With a More Complex Link

The links can be of any form

declare v_pdf_link varchar(255);

set v_pdf_link = '
<div class="pdfblock">
  <a href="{#url}"><img class="pdficon" src="user/images/pdf.svg" title="pdf"><div>{#title}</div></a>
</div>
';

select 'dbr.css','
.pdficon{margin-left:auto;margin-right:auto;height:50px;width:41px;display:inline-block}
.pdfblock {display:inline-block;margin-left: 10px;margin-right: 10px;}
';

select 'dbr.download';

select 'sample.pdf', 'A sample document' as 'title', v_pdf_link;

Serving a Directory as a List

One can use wildcards in the file parameter

select 'dbr.html', '<div></div><hr><h2>Files</h2><div><ul>';

select 'dbr.download';

select 'myfiles/*.*', null as 'title', '<li><a href="{#url}">{#title}</a></li>';

select 'dbr.html', '</ul></div>';