root/releases/0.1.1b/_files/download.php

Revision 2, 1.3 kB (checked in by sven, 3 years ago)

importing elgg-0.1.1a

Line 
1 <?php
2
3     // Download script
4     // Usage: http://URL/{username}/files/{folder_id}/{file_id}/{filename}
5     
6     // Run includes
7         require("../includes.php");
8         
9     // Initialise functions for user details, icon management and profile management
10         run("userdetails:init");
11         run("profile:init");
12         run("files:init");
13         
14     // If an ID number for the file has been specified ...
15     
16         if (isset($_REQUEST['id'])) {
17             $id = (int) $_REQUEST['id'];
18             
19     // ... and the file exists ...
20             
21             $file = db_query("select * from files where ident = $id");
22             if (sizeof($file) > 0) {
23                 
24                 $file = $file[0];
25                 
26     // ... and the owner of the file in the URL line hasn't been spoofed ...
27                 
28                 if (run("users:name_to_id",$_REQUEST['files_name']) == $file->owner) {
29     
30     // ... and the current user is allowed to access it ...
31                 
32                     if (run("users:access_level_check",$file->access) == true) {
33                                     
34     // Then output some appropriate headers and send the file data!
35
36                         $mimetype = run("files:mimetype:inline",$file->location);
37                         if ($mimetype == false) {
38                             $mimetype = "application/data";
39                         }
40
41                         header("Content-type: $mimetype");
42                         if ($mimetype == "application/data") {
43                             header('Content-Disposition: attachment');
44                         }
45                         readfile($file->location);
46                         
47                     }
48                     
49                 }
50             }
51         }
52
53 ?>
Note: See TracBrowser for help on using the browser.