From 2c291305a6f4aa1f1cf0f0dc8c07c5769d4a90ca Mon Sep 17 00:00:00 2001 From: Andrey Kuvshinov Date: Tue, 7 Apr 2020 18:22:55 +0300 Subject: [PATCH] add real pdf --- app/routes/price.php | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/app/routes/price.php b/app/routes/price.php index d0c00bc..baf9228 100644 --- a/app/routes/price.php +++ b/app/routes/price.php @@ -14,33 +14,37 @@ function priceid_kuri($id){ function file_kuri($hash) { - // $price = db_get("SELECT `pricename` FROM price WHERE `pricehash` = $hash LIMIT 1"); - // $id = $price['price_id']; + $price = db_get("SELECT `pricename` FROM price WHERE `pricehash` = $hash LIMIT 1"); - // $pdffile = "/vhosts/an/httpdocs/files/pdf/pdf/$id.pdf"; - - $pdfile = '/vhosts/anpdf/app/pub/files/promo.pdf'; - + if (!isset($price['price_id'])){ + header("HTTP/1.0 404 Not Found"); + return False; + } + + $id = $price['price_id']; + $pdfile = "/vhosts/an/httpdocs/files/pdf/pdf/$id.pdf"; $request = $_SERVER['REQUEST_URI']; $filename = basename($request); - if (file_exists($pdfile)) { - - if (ob_get_level()) { - ob_end_clean(); - } - - header("Content-Type: application/pdf; charset=UTF-8"); - header("Content-Length: ".filesize($pdfile)); - header("Content-Disposition: attachment; filename=\"{$filename}\""); - header("Content-Transfer-Encoding: binary"); - header("Cache-Control: must-revalidate"); - header("Pragma: no-cache"); - header("Expires: 0"); - readfile($pdfile); + if (!file_exists($pdfile)) { + header("HTTP/1.0 404 Not Found"); + return false; + } + + if (ob_get_level()) { + ob_end_clean(); } + + header("Content-Type: application/pdf; charset=UTF-8"); + header("Content-Length: ".filesize($pdfile)); + header("Content-Disposition: attachment; filename=\"{$filename}\""); + header("Content-Transfer-Encoding: binary"); + header("Cache-Control: must-revalidate"); + header("Pragma: no-cache"); + header("Expires: 0"); + readfile($pdfile); return;