<?php
// Scan directory and categorize items
function scan_directory($full) {
    $items = @scandir($full) ?: [];

    $folders = [];
    $images  = [];
    $others  = [];

    foreach ($items as $item) {
        if ($item === '.' || $item === '..') continue;

        $isDir = is_dir($full . '/' . $item);
        if ($isDir) {
            $folders[] = $item;
            continue;
        }

        // Always include files, even if they have no extension
        $ext = strtolower(pathinfo($item, PATHINFO_EXTENSION));

        if (in_array($ext, ['jpg','jpeg','png','gif','webp','heic','heif'])) {
            $images[] = $item;
        } else {
            $others[] = $item;
        }
    }

    return [$folders, $images, $others];
}
