 <?php
    $dir = '../../assets/img';
    $folders = scandir($dir);
    foreach ($folders as $folder) {
        if (!($folder == "." || $folder == "..") && is_dir($dir . '/' . $folder)) {
            $fold["name_fold"] = $folder;

            $dir_fold = '../../assets/img/' . $folder . "/";

            $files_fold = scandir($dir_fold);
            if (count($files_fold) != 2) {
                foreach ($files_fold as $img) {

                    $imageFileType = strtolower(pathinfo($dir_fold . "/" . $img, PATHINFO_EXTENSION));
                    if (!($img == "." || $img == "..") && (in_array($imageFileType, array('jpg', 'png', 'jpeg', 'gif', 'webp')))) {
                        $img_data["name_img"] = $img;
                        $img_data["dir_img"] = "/" . $folder . "/" . $img;
                        $img_data["dir_img_pre"] = $dir_fold . $img;
                        $img_data_list[] = $img_data;
                        $fold["list_file"] = $img_data_list;
                    }
                }
            } else {
                $img = "brak plików";
                $img_data["name_img"] = $img;
                $img_data["dir_img"] = "/" . $folder . "/" . $img;
                $img_data["dir_img_pre"] = $dir_fold . $img;
                $img_data_list[] = $img_data;
                $fold["list_file"] = $img_data_list;
            }
            $fold_list[$folder] = $fold;
            $fold["list_file"] = null;
            $img_data_list = null;
        }
    }
    ?>