<?php

class picfolder {
    public static function get($path, $id){
        if(!is_dir($path)){
            throw new ERROR("Picfolder -> invalid folder");}
         
        $filelist = array();
        $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
        while($it->valid()) {
            if (!$it->isDot()) {
                $filelist[] = $it->key();}
            $it->next();
        }        
        
        //random
        if($id == -1 || $id < 0 || $id >= count($filelist)){
        $id = rand(0, count($filelist)-1);}
        
        \SYSTEM\HEADER::PNG();
        return file_get_contents($filelist[$id]);
    }
}