0

選択したフォルダーから最新の画像を取得する次のコードがあります。

<?php 
foreach (glob('/home/pi/camera/*.jpg') as $f) {
    $list[] = $f;
}

sort($list);
?>

<img src="<?=array_pop($list);?>">

私がやりたいことは、ページを更新せずに、フォルダーに表示されるとすぐに最新の画像を表示することです。これはjqueryでできると思いますが、方法がわかりません。助けていただければ幸いです!

4

1 に答える 1

0

Use ajax to periodically load php script, where you will have code to check all files in that folder. It can return json with all files and you can check, if there is any new file, and then you can display it.

$.ajax({
    url: 'get_files_in_folder.php',
    success: function(data) {
        // here you can compare old files with that you got in "data"
    }
});

And the file get_files_in_folder.php should looks like:

<?php 
    foreach (glob('/home/pi/camera/*.jpg') as $f) {
        $list[] = $f;
    }

    sort($list);

    echo json_encode($list);
?>
于 2013-10-17T11:33:06.213 に答える