-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_document.php
More file actions
51 lines (40 loc) · 1.19 KB
/
view_document.php
File metadata and controls
51 lines (40 loc) · 1.19 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// Include required files
require_once 'incl/const.php';
require_once 'incl/Auth.php';
require_once 'incl/Database.php';
// Require authentication
//requireAuth();
// Get document ID
if (!isset($_GET['id'])) {
header('Location: documents.php');
exit;
}
$id = intval($_GET['id']);
// Check view permission
if (!canView('document', $id)) {
header('Location: index.php?error=access_denied');
exit;
}
try {
$document = getDocumentById($id);
if (!$document) {
header('Location: index.php?error=not_found');
exit;
}
// Check if file exists
if (!file_exists(DATA_DIR.'/uploads/'.$document['filename'])) {
die('File not found.');
}
// Set headers for file download
header('Content-Type: ' . $document['mime_type']);
header('Content-Disposition: inline; filename="' . $document['original_filename'] . '"');
header('Content-Length: ' . $document['file_size']);
header('Cache-Control: public, max-age=3600');
header('Pragma: public');
// Output file
readfile(DATA_DIR.'/uploads/'.$document['filename']);
exit;
} catch (Exception $e) {
die('Error: ' . htmlspecialchars($e->getMessage()));
}