false, 'error' => 'img directory not found']); exit; } $allowedExt = ['jpg','jpeg','png','gif','webp']; $images = []; $files = scandir($imgDir); if ($files === false) $files = []; foreach ($files as $f) { if ($f === '.' || $f === '..') continue; $path = $imgDir . DIRECTORY_SEPARATOR . $f; if (!is_file($path)) continue; $ext = strtolower(pathinfo($f, PATHINFO_EXTENSION)); if (!in_array($ext, $allowedExt, true)) continue; $images[] = $f; } // stable order natcasesort($images); $images = array_values($images); echo json_encode(['ok' => true, 'images' => $images], JSON_UNESCAPED_UNICODE);