-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfiles.php
More file actions
35 lines (30 loc) · 858 Bytes
/
files.php
File metadata and controls
35 lines (30 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* files
*
* @package Delus
* @author Sorokin Dmitry Olegovich
*/
// fetch bootstrap
require('bootstrap.php');
try {
// check if user not logged in (except for requests from mobile apps)
if (!valid_api_key() && !$system['system_public'] && !$user->_logged_in) {
user_login();
}
// check if file exists
$file = $system['uploads_directory'] . '/' . $_GET['file'];
if (!file_exists($file)) {
throw new Exception(__("File not found"));
}
// read the file contents and send the response
$handle = fopen($file, "rb");
$contents = fread($handle, filesize($file));
fclose($handle);
$content_type = mime_content_type($file);
header("Content-type: " . $content_type);
header("Content-disposition: inline; filename=" . $file);
echo $contents;
} catch (Exception $e) {
_error(__("Error"), $e->getMessage());
}