我使用它來顯示來自兩個目錄的最新圖像,其中來自攝像機的圖像每10秒上傳一次 代碼有效,但據我所知,每個目錄中可能會有數十個圖像相信代碼沒有針對這種情況進行優化。 此外,我每10秒重新加載整個頁面,可能會更高效地更新圖像。 有人可以幫助給我方向來優化這個嗎? 非常感謝。顯示目錄中的最新圖像
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
$base_url_east = 'East/snap/';
$base_url_south = 'South/snap/';
$newest_mtime_east = 0;
$show_file_east = 'BROKEN';
if ($handle = opendir($base_url_east)) {
while (false !== ($file = readdir($handle))) {
if (($file != '.') && ($file != '..') && ($file != '.htaccess')) {
$mtime = filemtime("$base_url_east/$file");
if ($mtime > $newest_mtime_east) {
$newest_mtime_east = $mtime;
$show_file_east = "$base_url_east/$file";
}
}
}
}
$newest_mtime_south = 0;
$show_file_south = 'BROKEN';
if ($handle = opendir($base_url_south)) {
while (false !== ($file = readdir($handle))) {
if (($file != '.') && ($file != '..') && ($file != '.htaccess')) {
$mtime = filemtime("$base_url_south/$file");
if ($mtime > $newest_mtime_south) {
$newest_mtime_south = $mtime;
$show_file_south = "$base_url_south/$file";
}
}
}
}
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body bgcolor="#000000">
<center>
<?php
print '<img src="' .$show_file_east. '" alt="Latest image uploaded" width="720" height="480">';
print '<img src="' .$show_file_south. '" alt="Latest image uploaded" width="720" height="480">';
?>
</center>
</body>
</html>
如何獲得目錄填充文件?一些腳本這樣做?或者只是手動? –
擺脫' chris85
當您上傳新圖像時,只需將其文件名保存到數據庫以檢索其文件名,而不是遍歷所有文件並獲取最新的文件。 –