0 ) { unlink( $path.$file ); } $file = $next_file; $timestamp = $next_timestamp; } } $next_file = readdir($cachedir); } closedir( $cachedir ); if( $file!='' ) { $pic_file = file_get_contents( $path.$file ); } return( $pic_file != '' ); } /* Trouve l'image la plus recente dans un repertoire * "%s%02d%02d.jpg" */ function brute_image_find( $path, $format, &$file ) { $h = 0; $m = 0; $timestamp = 0; for( $i = 0; $i < 60; $i++ ) { $this_file = sprintf($format,$m); $this_time = filemtime($path.$this_file); if( $this_time > $timestamp ) { $timestamp = $this_time; $file = $this_file; } $m = $m + 1; if( $m > 59 ) { $m = 0; $h = $h +1; if( $h > 23 ) { $h = 0; } } } } function find( $path, $format, $tolerance, &$file ) { $now = time(); $timestamp = filemtime($path.$file); if( $now - $timestamp > $tolerance ) { /* $this_file = sprintf($format, strftime("%M",$now)); $this_time = filemtime($path.$this_file); echo $this_file." ".$file." ".($now - $this_time)." )))"; if( ($now - $this_time) <= $tolerance ) { $file = $this_file; } */ return( FALSE ); } return( TRUE ); } function cache_write( $path, $string ) { $tempfile = tempnam($path,"pnc"); $file = fopen($tempfile,"w"); fwrite($file,$string); fclose($file); } $tolerance = 60; /* En seconde */ $cache_file = ''; $cache_path = './cache/'; $pic_file = ''; $pic_path = './'; $pic_format1 = 'webcam_thumb-%02d.jpg'; $pic_format2 = 'webcam_thumb-%s.jpg'; if( cache_find( $cache_path, $pic_file )===FALSE ) { brute_image_find( $pic_path, $pic_format1, $pic_file ); cache_write( $cache_path, $pic_file ); } else { if( !find( $pic_path, $pic_format2, $tolerance, $pic_file ) ) {; brute_image_find( $pic_path, $pic_format1, $pic_file ); cache_write( $cache_path, $pic_file ); } } //$end = microtime_float(); //echo "$pic_file :".(($end - $start)*1000)."ms"; /*header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header('Content-Length: '.filesize($pic_file)); header('Content-type: image/jpeg'); readfile($pic_file);*/ //echo $pic_file; header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header('Content-Length: '.filesize($pic_file)); header('Content-type: image/jpeg'); readfile($pic_file); ?>