I'm trying to implement the provided script into a wordpress blog. I'm using execPHP to allow me to use PHP inside of the pages of the blog. The script will take a directory name, then randomly select 6 pictures from that directory and outputs the HTML to display those images. The script works perfectly for the home page of my blog but when I try to apply it to one of the peripheral pages it will not display, even if I point them to the same directory.
This is the first segment, placed at the top of the blog:
<?php
function getRandomFromArray($ar) {
mt_srand( (double)microtime() * 1000000 );
$num = array_rand($ar);
return $ar[$num];
}
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;
}
?>
And then this segment is placed where I need the pictures:
<?php $path = 'Images/';
$imgList = getImagesFromDir($path);
$img = getRandomFromArray($imgList);
$img2 = getRandomFromArray($imgList);
$img3 = getRandomFromArray($imgList);
$img4 = getRandomFromArray($imgList);
$img5 = getRandomFromArray($imgList);
$img6 = getRandomFromArray($imgList);
echo"<img src=\"" . $path . $img . "\" alt=\"Wallpaper Preview\" />";
echo"<img src=\"" . $path . $img2 . "\" alt=\"Wallpaper Preview\" />";
echo"<img src=\"" . $path . $img3 . "\" alt=\"Wallpaper Preview\" />\n";
//break
echo"<img src=\"" . $path . $img4 . "\" alt=\"Wallpaper Preview\" />";
echo"<img src=\"" . $path . $img5 . "\" alt=\"Wallpaper Preview\" />";
echo"<img src=\"" . $path . $img6 . "\" alt=\"Wallpaper Preview\" />";
?>
So for example, if I call the script at www.myblog.com it works, but if I try to call it at www.myblog.com/?page_id=11 it doesn't. Even when I hard code the path to the directory, such as http://www.myblog.com/images/summerphotos/ it won't work (for either page actually).
All help would be greatly appreciated! I've been stuck on this seemingly simple project for almost two days now, and I'd like to get moving again