From 02a53db50c17ba97e017b506cc9508ecf2887118 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:08:47 +0100 Subject: [PATCH] add recipe/img controller action --- Controllers/RecipeController.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php index de875d1..514b858 100644 --- a/Controllers/RecipeController.php +++ b/Controllers/RecipeController.php @@ -73,4 +73,27 @@ final class RecipeController )); } + public function imgAction(Array $A_urlParams = null, Array $A_postParams = null, Array $A_getParams = null) + { + if (count($A_urlParams) !== 1 ) throw new HTTPSpecialCaseException(404); + + $O_recipeModel = new RecipeModel(); + $A_recipe = $O_recipeModel->getRecipeByID($A_urlParams[0]); + + if (!isset($A_recipe)) { + throw new HTTPSpecialCaseException(404); + } + + header("Content-Type: image"); + if ($A_recipe["IMG"] === null) { + echo file_get_contents(Constants::rootDir()."/static/img/default_recipe.jpg"); + } else { + echo $A_recipe["IMG"]; + } + + + + return Utils::RETURN_RAW; + } + }