From 127d8394eda517cbe9f1a0b94e6f5ac303786c1a Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 28 Jul 2016 10:09:30 +0200 Subject: v0.5.1 secret files --- include/file-get.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 include/file-get.php (limited to 'include') diff --git a/include/file-get.php b/include/file-get.php new file mode 100644 index 0000000..b3f575d --- /dev/null +++ b/include/file-get.php @@ -0,0 +1,47 @@ +. + */ + +require_once('./conf.php'); + +$filename = $_REQUEST['name']; +$filepath = Constants::files_folder . $filename; + +$key = $_REQUEST['key']; + +$files = BusinessAdmin::getFiles($_pdo, ['`filename`=?'], [$filename]); +if (count($files) == 0 || !file_exists($filepath) || is_dir($filepath)) { + http_response_code(404); + header('Content-type: text/plain'); + echo "$filename could not be found"; +} elseif (array_pop($files)->secret_key != $key) { + http_response_code(403); + header('Content-type: text/plain'); + echo "incorrect key"; +} else { + header('Content-type: ' . mime_content_type($filepath)); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + readfile($filepath); +} -- cgit v1.2.3