diff options
author | Malf Furious <m@lfurio.us> | 2016-03-31 21:26:52 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2016-03-31 21:26:52 -0400 |
commit | 8ffc128d193929d9197af705974862b92a85a0fb (patch) | |
tree | d6ee85131fe0132f04570cbf9e2080e8345913e6 | |
parent | b701b45ae6e293c4d1bb89f068bf20b00a9ac53b (diff) | |
download | scrott-8ffc128d193929d9197af705974862b92a85a0fb.tar.gz scrott-8ffc128d193929d9197af705974862b92a85a0fb.zip |
Add heads() function to file.php
This function asserts that the requester is logged in and that the file exists before either fpassthru()-ing the contents
or returning early.
Diffstat (limited to '')
-rw-r--r-- | app/file.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/file.php b/app/file.php index 17044f3..3c34a89 100644 --- a/app/file.php +++ b/app/file.php @@ -25,6 +25,30 @@ class Resource extends Framework case "img/heads": $this->heads($file); break; } } + + /* + * Request a user head (user image) + * Requester must be currently logged in + */ + function heads($file) + { + if (!$this->getCurrentUser()) + return; + + if (!file_exists("assets/img/heads/" . $file)) + $file = "null.jpg"; + + $file = "assets/img/heads/" . $file; + $f = fopen($file, "rb"); + + if (!$f) + return; + + header("Content-type: " . mime_content_type($file)); + header("Content-length: " . filesize($file)); + fpassthru($f); + fclose($f); + } } $res = new Resource(); |