T
tim
Guest
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 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. All help would be greatly appreciated!
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. All help would be greatly appreciated!