<?php
error_reporting(false);

header('Content-Type: application/json');
header("Cache-Control: no-cache");
header("Pragma: no-cache");


$imagens = array();

$cod = $_REQUEST['cod_tv'];

//$cod = 1;

if($cod != '') {

    $path = 'images/'.$cod;  
    
        if (is_dir($path)) {        

            foreach (new DirectoryIterator($path) as $file) {
                
                if ($file->isDot()) continue;
                $fileName = $file->getFilename();
                $pieces = explode('.', $fileName);
                $date = explode('-', $pieces[2]);
                $filetypes = array(
                    "jpg",
                    "jpeg",
                    "png"
                );
                
                $filetype = pathinfo($file, PATHINFO_EXTENSION);
                
                if (in_array(strtolower($filetype), $filetypes)) {
                    $imagens[] = $path . '/' . $fileName;
                }
                
            }
            
          
        } /* else {
            echo $namePreferred . ' are not ready.</p>';
        } */

}


shuffle($imagens);
echo json_encode($imagens); 

?>