54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
require_once('./include/db_info.inc.php');
|
|
require_once('./include/courseware.inc.php');
|
|
|
|
$method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
|
|
if ($method !== 'GET' && $method !== 'HEAD') {
|
|
header('Allow: GET, HEAD');
|
|
http_response_code(405);
|
|
exit;
|
|
}
|
|
|
|
if (isset($OJ_NEED_LOGIN) && $OJ_NEED_LOGIN && !isset($_SESSION[$OJ_NAME . '_' . 'user_id'])) {
|
|
http_response_code(401);
|
|
exit;
|
|
}
|
|
|
|
$slug = isset($_GET['deck']) ? strval($_GET['deck']) : '';
|
|
$found = courseware_resolve_pptx($slug);
|
|
if ($found === null) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
|
|
$path = $found['path'];
|
|
$filename = $found['filename'];
|
|
$size = @filesize($path);
|
|
if ($size === false) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
|
|
$fp = null;
|
|
if ($method !== 'HEAD') {
|
|
$fp = fopen($path, 'rb');
|
|
if ($fp === false) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$mime = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
|
|
header('Content-Type: ' . $mime);
|
|
header('Content-Length: ' . $size);
|
|
header('Content-Disposition: ' . courseware_content_disposition($filename));
|
|
header('X-Content-Type-Options: nosniff');
|
|
header('Cache-Control: private, no-store');
|
|
|
|
if ($method === 'HEAD') {
|
|
exit;
|
|
}
|
|
|
|
fpassthru($fp);
|
|
fclose($fp);
|