<?php
$dir = __DIR__ . "/assets/data_wajah"; // folder data wajah
$files = array_diff(scandir($dir), ['.', '..']);

$faces = [];
foreach ($files as $file) {
    if (preg_match('/\.(jpg|jpeg|png)$/i', $file)) {
        $name = pathinfo($file, PATHINFO_FILENAME);
        $faces[] = [
            "name" => $name,
            "url"  => "/assets/data_wajah/" . $file
        ];
    }
}

header('Content-Type: application/json');
echo json_encode($faces);
