File Downloads
Commands
dbr.download - Serves files from the filesystem
Syntax
select 'dbr.download', ['dynamic' | null [, 'readfile' | 'x-sendfile' ]]
Explanation
The command enables secure serving of files from the filesystem.
The command is configured through environment settings. 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, conserving PHP resources. Configuring X-Sendfile requires setup on the web server. Files can be served with session-unique URLs (dynamic) or user-unique URLs (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 code contains 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;
File download statistics are recorded in the mydbr_file_downloads table.
Examples
Serving a Single File as a Sample Link and a Direct HTML Code
myDBR replaces the #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=""></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=""><img class="pdficon" src="user/images/pdf.svg" title="pdf"><div></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
Wildcards can be used 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=""></a></li>';
select 'dbr.html', '</ul></div>';