| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
// Usage: http://URL/{username}/files/{folder_id}/{file_id}/{filename} |
|---|
| 5 |
|
|---|
| 6 |
// Run includes |
|---|
| 7 |
require("../includes.php"); |
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
run("userdetails:init"); |
|---|
| 11 |
run("profile:init"); |
|---|
| 12 |
run("files:init"); |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
if (isset($_REQUEST['id'])) { |
|---|
| 17 |
$id = (int) $_REQUEST['id']; |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
$file = db_query("select location, access, originalname from files where ident = $id"); |
|---|
| 22 |
if (sizeof($file) > 0) { |
|---|
| 23 |
|
|---|
| 24 |
$file = $file[0]; |
|---|
| 25 |
|
|---|
| 26 |
if (run("users:access_level_check",$file->access) == true) { |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|---|
| 30 |
|
|---|
| 31 |
$tstamp = filemtime($file->location); |
|---|
| 32 |
$lm = gmdate("D, d M Y H:i:s", $tstamp) . " GMT"; |
|---|
| 33 |
|
|---|
| 34 |
if ($if_modified_since == $lm) { |
|---|
| 35 |
header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified"); |
|---|
| 36 |
exit; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
if ($tstamp < time()) { |
|---|
| 41 |
header("Last-Modified: " . $lm); |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
$mimetype = run("files:mimetype:determine",$file->originalname); |
|---|
| 47 |
if ($mimetype == false) { |
|---|
| 48 |
$mimetype = "application/octet-stream"; |
|---|
| 49 |
} |
|---|
| 50 |
if ($mimetype == "image/jpeg" || $mimetype == "image/png") { |
|---|
| 51 |
$icon = url . "units/phpthumb/phpThumb.php?w=90&src=" . urlencode($file->location); |
|---|
| 52 |
$mimetype = "image/jpeg"; |
|---|
| 53 |
} else { |
|---|
| 54 |
$mimetype = "image/png"; |
|---|
| 55 |
$icon = path . "_files/file.png"; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
// Also to override PHP's default "DON'T EVER CACHE THIS EVER" header |
|---|
| 60 |
header("Cache-Control: private"); |
|---|
| 61 |
|
|---|
| 62 |
header("Content-type: $mimetype"); |
|---|
| 63 |
readfile($icon); |
|---|
| 64 |
|
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
?> |
|---|