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