The random image is generated by the following statement on my main page:
<?php include('random.image.php'); ?>
Below is the listing for the file 'random.image.php'. The script uses a text file called 'images.inline.txt' which contains one line of HTML code for each image. Basically, the PHP script substitutes an HTML <IMG> for itself.
When the script DOESN'T WORK, no HTML is substituted into the main page, and therefore I get no image.
random.image.php
<?php
/************************************
Title........: Random Image Picker
Filename.....: random.image.php
Author.......: Richard Heyes
Version......: 1.1
Notes........:
Last changed.: 03/06/2000
Last change..: Code clean up, added link feature.
**************************************/
$filename = 'images.inline.txt';
$use_mt_rand = 1;
$inline = 1;
/************************************
Open file and read in the contents.
**************************************/
$file_array = file($filename);
/************************************
Determine which random function to use.
**************************************/
if($use_mt_rand == 1){
$randseed = 'mt_srand';
$randfunc = 'mt_rand';
}else{
$randseed = 'srand';
$randfunc = 'rand';
}
/************************************
Get a random value. If there is only
one line, then no need to use random
functions.
*************************************/
if(count($file_array) > 1){
$randseed((double)microtime()1000000);
$randval = $randfunc(0,(count($file_array)-1));
}else{
$randval = 0;
}
/************************************
If using in inline mode create the
image tag. If not simply output the
image.
**************************************/
if($inline == 1){
echo $file_array[$randval];
}else{
/***************************************
** Determine the image header type to send.
***************************************/
$extension = substr($file_array[$randval], (strrpos($file_array[$randval], '.')+1));
if($extension == 'tif') $extension = 'tiff';
if($extension == 'jpg') $extension = 'jpeg';
header('Content-Type: image/'.$extension);
header('Pragma: no-cache');
header('Expires: 0');
readfile(trim($file_array[$randval]));
}
?>