Hi All,
I was wondering if anyone could have a look at this code and explain why the page doesn't display an image? Basically I have a camer taking pictures very few minutes and I want to display the latest one.
<!DOCTYPE html>
<html>
<head>
<title>Picture</title>
</head>
<body>
<a href="index.html">Return home</a>
<h2>Latest Image from the camera</h2>
<img src="<?php echo $path . $img ?>" alt="Latest picture" style="width:304px;height:228px" />
<?php
$root = '';
$path = 'images/';
$imgList = getImagesFromDir($root . $path);
$img = getRandomFromArray($imgList);
function getImagesFromDir($path) {
$images = array();
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// checks for gif, jpg, png
if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) {
$images[] = $img_file;
}
}
closedir($img_dir);
}
return $images;
}
function getlastFromArray($ar) {
$num = end($ar);
return $ar[$num];
}
?>
</body>
</html>
I'd appreciate any pointers, thank you.
Ben