Hi everyone,
I am trying to create a random image script that usues a slightly different approach from methods I've seen such as just getting an image url...
What I want to do is make <img src="randimage.php"> give me a random image. I've written most of my script, but am having massive headaches with trying to print it out.... Here's my script:
$images = array(
"1" => "test1.gif",
"2" => "test2.jpg"
);
// Select the random image
srand ((double) microtime() * 10000000);
$rand_select = array_rand($images);
// Get the Content-Type
$type = substr($images[$rand_select],-3);
if($type == "jpg") $type = "jpeg";
header("Content-type: image/${type}");
$fp = fopen("$images[$rand_select]","rb");
$file = fread($fp,filesize("$images[$rand_select]"));
fclose($fp);
echo $file;
Up to here works fine, but if I try to echo out $file, the script seems to just sit there (does nothing.. no errors or anything, but it NEVER loads)...
I checked the header.. that was fine...
Then I removed the 'echo $file;' and everything works (except of course the image doesn't show up....)
Any help would be greatly appreaceated 🙂
-Josh