File downlaods

Commands

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

Syntax

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

Explanation

The command allows serving files from the filesystem securely.

Environment settings hold the configuration of the command. The files can be served with two methods: PHP's readfile and X-Sendfile. The default method is readfile. The X-Sendfile allows myDBR to redirect the request for a file to the webserver, hence freeing PHP resources. The X-Sendfile requires one to configure the webserver to handle the process. The files served are served per unique URL for each user's session (dynamic) or per unique to the user (static). The compulsory base directory defines the root directory from which the files are served.

One can override the default mode (static/dynamic) and method (readfile/x-sendfile) with the option for the command.

The result set following the command generates the download links. The first column is the path to the files (relative to the base-directory). The last column in the result set defines the HTML code that is being used to show the link. The variables in the HTML codes are filled with column values. The predefined #url variable will be replaced with the generated download URL. The HTML can be a 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 fied #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>';