Created a new folder in _templates to house site icons. Put the new RSS standard...
[elgg.git] / _files / download.php
blobffde9fa207a37f432693482c80199e198f31a916
1 <?php
3 // Download script
4 // Usage: http://URL/{username}/files/{folder_id}/{file_id}/{filename}
6 // Run includes
7 require_once(dirname(dirname(__FILE__))."/includes.php");
9 // Initialise functions for user details, icon management and profile management
10 run("userdetails:init");
11 run("profile:init");
12 run("files:init");
14 // If an ID number for the file has been specified ...
15 $id = optional_param('id',0,PARAM_INT);
16 if (!empty($id)) {
17 // ... and the file exists in the database ...
18 if ($file = get_record('files','ident',$id)) {
19 // ... and the owner of the file in the URL line hasn't been spoofed ...
20 $files_name = optional_param('files_name');
21 if (run("users:name_to_id",$files_name) == $file->owner
22 || run("users:name_to_id",$files_name) == $file->files_owner) {
24 // ... and the current user is allowed to access it ...
26 if (run("users:access_level_check",$file->access) == true || $file->owner == $_SESSION['userid']) {
28 // ... and the file exists on disk ...
30 // Send 304s where possible, rather than spitting out the file each time
31 $if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
33 $tstamp = filemtime($CFG->dataroot . $file->location);
34 $lm = gmdate("D, d M Y H:i:s", $tstamp) . " GMT";
36 if ($if_modified_since == $lm) {
37 header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified");
38 exit;
41 // Send last-modified header to enable if-modified-since requests
42 if ($tstamp < time()) {
43 header("Last-Modified: " . $lm);
46 // Then output some appropriate headers and send the file data!
47 require_once($CFG->dirroot.'/lib/filelib.php');
48 $mimetype = mimeinfo('type',$file->location);
50 // "Cache-Control: private" to allow a user's browser to cache the file, but not a shared proxy
51 // Also to override PHP's default "DON'T EVER CACHE THIS EVER" header
52 header("Cache-Control: private");
54 header("Content-type: $mimetype");
55 if ($mimetype == "application/octet-stream") {
56 header('Content-Disposition: attachment');
58 readfile($CFG->dataroot . $file->location);