summaryrefslogtreecommitdiffstats
path: root/app/df.php
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-06-04 14:45:23 -0400
committerMalf Furious <m@lfurio.us>2017-06-04 14:45:23 -0400
commit138348bbd1318a3bc2ee5112eee44d385b21751e (patch)
tree5606031b4f192af7cf7256483b4427b596cce980 /app/df.php
parent5f50dd6b09f8458b62ce00fda83debca66bd8544 (diff)
downloadscrott-138348bbd1318a3bc2ee5112eee44d385b21751e.tar.gz
scrott-138348bbd1318a3bc2ee5112eee44d385b21751e.zip
Update df function serveResource()
Added optional parameter for resource's filename. If given, a Content-Disposition header will be delivered to the client.
Diffstat (limited to 'app/df.php')
-rw-r--r--app/df.php10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/df.php b/app/df.php
index a425d57..9581cae 100644
--- a/app/df.php
+++ b/app/df.php
@@ -31,15 +31,19 @@ require_once "class/user.class.php";
* request. When finished, this function will exit PHP and terminate
* this script.
*/
-function serveResource(string $uri) : void
+function serveResource(string $uri, ?string $filename = NULL) : void
{
$f = fopen($uri, "rb");
if (!$f)
exit;
- header("Content-type: " . mime_content_type($uri));
- header("Content-length: " . filesize($uri));
+ header("Content-Type: " . mime_content_type($uri));
+ header("Content-Length: " . filesize($uri));
+
+ if ($filename)
+ header("Content-Disposition: attachment; filename='" . $filename . "'");
+
fpassthru($f);
fclose($f);