diff options
-rw-r--r-- | app/df.php | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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); |