FIX: Removed forbidden page, added to secure.php
[phorkie.git] / www / raw.php
1 <?php
2 /**
3  * Displays a file
4  */
5 namespace phorkie;
6 require_once 'www-header.php';
7 if ($GLOBALS['phorkie']['auth']['secure'] == 2) {
8     include_once 'secure.php';
9 }
10 $repo = new Repository();
11 $repo->loadFromRequest();
12
13 if (!isset($_GET['file']) || $_GET['file'] == '') {
14     throw new Exception_Input('File name missing');
15 }
16
17 $file = $repo->getFileByName($_GET['file']);
18 $mimetype = $file->getMimeType();
19 if ($mimetype === null) {
20     $mimetype = 'text/plain';
21 }
22 header('Content-Type: ' . $mimetype);
23 if ($repo->hash === null) {
24     //IIRC readfile is not so memory-intensive for big files
25     readfile($file->getFullPath());
26 } else {
27     echo $file->getContent();
28 }
29 ?>