If you have files that you want your users to only be able to download by going through your web page, you can do so with the file download management tool.
Your web page must be a PHP web page. You need to add a few lines to the very top of your web page to tell the download management tool where the files are, and which files are authorized for download:
<? require_once('/web/includes/sso_portal.phpi'); $sso->authenticate(); require_once('/web/includes/downloads.phpi'); $files = new FileManager('/path/to/directory'); $files->download(); ?>
This must be at the very top of your web page. There cannot be any HTML before it, nor even any spaces or blank lines. Any stuff above the PHP code listed above will cause the downloads to fail.
If files become corrupted or unopenable after downloading, it is probably because your web page has something before the PHP, or one of your include files has something before or after the PHP.
You can modify authentication as normal and note that home.sandiego.edu must use sso_www.phpi.
Store your files outside Sites
Since you’re doing this to require people to go through a web page (requiring a login) before they can download files, store the files outside of your Sites folder. Otherwise they’ll be able to bypass your login page and download the files directly. Instead, create a special folder for downloads in your home directory, and store your downloads there.
You can use a secure ftp program to upload your files to the storage folder.
Showing available files
You’ll presumably want to show the files that are available for download. You can use $files->show() for this:
<? $files->show(); ?>
This will display the downloads in alphabetical order, along with the size of the file and the time it was last modified. They will be displayed in a table of class “files”. You can modify the table’s display using style sheets as normal.
If you’d prefer a simple list of files without the size or date information, use the “listing” method instead.
<? $files->listing(); ?>
The list is a “ul” list with the style “files”.
No file extensions
If you don’t want to show file extensions, use:
<? $files->hideExtensions(); ?>
This will cause listings to not show file extensions, such as .pdf or .zip.
You can also create your own links to the downloads if you want; the links must be to the full filename (including index.php if that’s the filename) of the page displaying the downloads, a slash, and then the filename of the download.
The safest way to get the link URLs for creating custom links is to use $files->show() to display them, copy the links from there, and then remove $files->show().
By default, the system lets the browser decide whether to show a document in the browser window or download it to the visitor’s downloads folder. If you want to force the browser to always download the chosen document, add this option:
Make sure you put it after the download manager is created, but before you tell it to handle downloads.
Require login on download
As long as you include one of the single sign-on plugins before you set up the download manager, logins will be required to download any of your files via your web form. If you have the page set up so that logins are not required, and they attempt to download a file, it will display the login form before letting them view or download the file.
More than one folder?
If you want to show downloads from multiple folders, all you need to do is create multiple FileManagers. For example:
$files = new FileManager('/path/to/files'); $files->download();
$images = new FileManager('/path/to/images'); $images->download() …
<h2>Files:</h2> <? $files->show(); ?>
<h2>Images:</h2> <? $images->show(); ?>
The old version
This PHP include file replaces a very old one using /web/includes/downloads.php (no ‘i’). If you need a feature from that older version, let me know.