diff --git a/php/get.php b/php/get.php index b1f345a..30a88d2 100644 --- a/php/get.php +++ b/php/get.php @@ -6,47 +6,47 @@ define("IMG_URL", "img/"); main(); function main(): void { - $data = json_decode(file_get_contents('php://input'), true); - $array = []; + $data = json_decode(file_get_contents('php://input'), true); + $array = []; - $category = $data["category"]; - $directory = IMG_DIR.$category; - if (!is_dir($directory)) return; - foreach (scandir($directory) as $file) { - if ($file === ".") continue; - if ($category === "" && $file === "..") continue; + $category = $data["category"]; + $directory = IMG_DIR.$category; + if (!is_dir($directory)) return; + foreach (scandir($directory) as $file) { + if ($file === ".") continue; + if ($category === "" && $file === "..") continue; - if ($category != "") $file = $category.'/'.$file; - $is_dir = is_dir(IMG_DIR.$file); - if (!$is_dir && !is_valid_file_type($file)) continue; + if ($category != "") $file = $category.'/'.$file; + $is_dir = is_dir(IMG_DIR.$file); + if (!$is_dir && !is_valid_file_type($file)) continue; - $file_item = []; - $file_item["is_dir"] = $is_dir; - $file_item["url"] = ROOT_URL.IMG_URL.$file; - array_push($array, $file_item); - } - echo json_encode($array); + $file_item = []; + $file_item["is_dir"] = $is_dir; + $file_item["url"] = ROOT_URL.IMG_URL.$file; + array_push($array, $file_item); + } + echo json_encode($array); } function is_valid_file_type(string $filename): bool { - $file_extensions = [ - // Image extensions - 'jpg', - 'jpeg', - 'png', - 'gif', - 'tiff', - 'bmp', - 'webp', - 'svg', - // Video extensions - 'mp4', - ]; + $file_extensions = [ + // Image extensions + 'jpg', + 'jpeg', + 'png', + 'gif', + 'tiff', + 'bmp', + 'webp', + 'svg', + // Video extensions + 'mp4', + ]; - foreach ($file_extensions as $file_extension) { - if (str_ends_with($filename, $file_extension)) return true; - } - return false; + foreach ($file_extensions as $file_extension) { + if (str_ends_with($filename, $file_extension)) return true; + } + return false; } ?>