Display a secure tree view of files for download in Sitelok

Sitelok allows you to secure download links using the siteloklink() function. This works by generating a secure link which only works for the logged in user and hides the location where the file is located. In most cases this works fine but if you have a whole folder of files (perhaps with subfolders) it might be hard to create all the links. To make a neat solution for this situation we have modified the open source  phpfiletree script so that it will display files and folders from a Sitelok download location and automatically secure links. You can place the file tree object on any secured page and looks something like this.

You can download the files here (sitelokfiletree.zip)

1) First of all we should make a Sitelok file location that points to where you store your files. This needs to be on the same domain as Sitelok. To do this go to Tools - Configuration and scroll down to Download Locations. Create an additional location called files and enter the full file path to the folder on your server. It should look something like this.

Here I created a new obscure folder named ri9dfvuhi43wfj but you can point to an existing folder if you wish. We will secure it later anyway.
2) Upload the phpfiletree folder from the zip file (see link above) to the root of your site. There is a test page called filetreetest.php which you can upload to the root of your site as well if you wish.
3) In the Sitelok snippet at the top of the page where you want the file tree to appear add this line (adjust path if necessary)
so for example like this
4) In the HEAD section of the page add these lines (adjust path if necessary)
<link href="/phpfiletree/styles/default/default.css" rel="stylesheet" type="text/css" media="screen" />                  
<script src="/phpfiletree/php_file_tree.js" type="text/javascript"></script>

5) At the point in the page where you want it to appear insert

<?php echo php_file_tree($FileLocations["files"], "files", array("gif", "jpg", "jpeg", "png","pdf")); ?>

You can adjust the list of file types to show. Other types will be ignored.

6) Check that everything works as expected. If you use an obscure folder name then the files won't be found by users or search engines etc. However you can also block access to the folder via the internet by adding a .htaccess file to the folder containing the following.
order allow,deny
deny from *