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