blob: b671a5f1c156f1d5771a9d750092f906e8701d2e (
plain)
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
36
|
<?php
namespace app\controllers\cms;
use Registry;
use Render;
use app\controllers\Auth;
use app\models\cms\Course_model;
class Course {
/** serve file by file_path
* (request is valid only for admin users)
*
* @param $file_path (string): relative file path
* GET @param type (string) : media-type of file
*/
public static function serve_file($file_path)
{
// check privileges
if (Auth::is_admin()) { // TODO: -OR- has prvivilege
$media_type = Registry::get('REQUEST')->GET['type']; // get media-type
$real_path = MEDIA_STORAGE_ROOT . $file_path; // construct real path
if (!file_exists($real_path)) {
Render::view('error/404');
} else {
Render::file($real_path, $media_type);
}
}
}
}
|