我正在尝试每 3 秒计算一次目录的大小。计算成功并显示大小,但不会更新。这是目前的代码:
<script type='text/javascript'>
window.onload = sizeRefresh;
function updatesize() {
$dir_size = <?php
$dir = "pics";
function dirSize($directory) {
$size = 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
$size+=$file->getSize();
}
echo json_encode(round($size/1024,0) . " KB<br>" . round($size/1024/1024,0) . "MB<br>" . round($size/1024/1024/1024,0) . "GB" );
}
dirSize($dir)
?>;
var hsize = document.getElementById('sizemark');
hsize.innerHTML = $dir_size
}
function sizeRefresh() {
setInterval("updatesize()", 3000);
}
</script>
<h1 id='sizemark' > size </h1>
我究竟做错了什么?
谢谢你。