forked from mkucej/i-librarian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattachment.php
60 lines (52 loc) · 1.95 KB
/
attachment.php
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
52
53
54
55
56
57
58
59
60
<?php
include_once 'data.php';
include_once 'functions.php';
session_cache_limiter('none');
session_write_close();
//PATH SUPPLEMENT OR PNGS
if (isset($_GET['attachment'])) {
$path = IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($_GET['attachment']);
$file = str_replace("/", "", $_GET['attachment']);
$file = str_replace("\\", "", $file);
}
if (isset($_GET['png'])) {
$path = IL_IMAGE_PATH;
$file = str_replace("/", "", $_GET['png']);
$file = str_replace("\\", "", $file);
}
if (isset($_GET['rtf'])) {
$path = IL_TEMP_PATH . DIRECTORY_SEPARATOR . 'lib_' . session_id();
$file = str_replace("/", "", $_GET['rtf']);
$file = str_replace("\\", "", $file);
}
if (!empty($file) && is_file($path . DIRECTORY_SEPARATOR . $file)) {
if (isset($_GET['attachment']))
$filename = substr(urldecode($file), 5);
if (isset($_GET['png']))
$filename = urldecode($file);
if (isset($_GET['rtf']))
$filename = urldecode($file);
$type = 'application/octet-stream';
if (extension_loaded('fileinfo')) {
$finfo = new finfo(FILEINFO_MIME);
$type = $finfo->file($path . DIRECTORY_SEPARATOR . $file);
}
//MODE INLINE OR ATTACHMENT
$mode = 'attachment; filename="' . $filename .'"';
if (isset($_GET['mode']) && $_GET['mode'] == 'inline')
$mode = 'inline';
//CACHE THIS FILE
$seconds_to_cache = 604800;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: private");
header("Cache-Control: max-age=$seconds_to_cache");
header("Cache-Control: private");
header('Last-Modified: ' . gmdate(DATE_RFC1123, filemtime($path . DIRECTORY_SEPARATOR . $file)));
header("Content-Type: " . $type);
header("Content-Disposition: " . $mode);
header('Content-Length: ' . filesize($path . DIRECTORY_SEPARATOR . $file));
ob_clean();
flush();
readfile($path . DIRECTORY_SEPARATOR . $file);
}