Per tutti coloro che utilizzano telecamere che pubblicano le immagini su un ftp con nome diverso ogni foto, lo script utilizzato in questo sito è il seguente, sviluppato da me:
Caratteristiche: Refresh pagina ogni 20 min; cancellazione delle foto con data risalente al giorno prima e pubblicazione del timestamp della foto visualizzata
<?php
//nuovo script
$arrayfile = Array();
function ordina($file1,$file2)
{
$tempo1 = ($file1);
$tempo2 = ($file2);
return ($tempo1 < $tempo2) ? 1 : -1;
}
if ($handle = opendir('foto/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..") {
$arrayfile[]=$file;
}
}
closedir($handle);
usort($arrayfile,'ordina');
}
?>
<?php
//Cancella File
// setup timezone and get timestamp for yesterday
date_default_timezone_set('Europe/Athens'); // change to yours
$yesterday = strtotime('-1 day', time());
// setup path to cache dir and initialize iterator
$path = realpath('foto/'); // change to yours
$objects = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path));
// iterate over files in directory and delete them
foreach($objects as $name => $object){
if ($object->isFile() && ($object->getCTime() < $yesterday)) {
unlink($object);
//echo PHP_EOL, 'deleted ' . $object;
}
}
?>
<html xmlns="
www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kioni.net</title>
<script>
<!--
//Refresh Automatico della Pagina
//enter refresh time in "minutes:seconds". Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="21:00"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}
window.onload=beginrefresh
//-->
</script>
</head>
<body>
<p align="center"><img src="foto/<?php echo $arrayfile[0]; ?>" ></p>
<?php
// variabile che prende l'informazione.
$last_time_modified = filemtime("foto/$arrayfile[0]");
// formatta la data
$last_mod = "Foto del " . date("j/m/Y h:i:s A e", $last_time_modified);
print $last_mod;
?>
</font>
</p>
<p align="center"><font face="Verdana">Refresh automatico ogni 20 minuti.</font>
</p>
</body>
</html>
Cordiali saluti a tutti i webmaster!
Mattia480