Jump to content

PHP image rotator help


john010117

Recommended Posts

I have used one of your scripts called "Random Image Rotator". It's supposed to display a random image every time you load up the page. I've inserted the code into a file named "rotate.php" and have changed the necessary variables to make it work. All my images are in the "images" folder, and I haven't placed this file in a folder. Here's the code for it:

[code]<?php
// Change the folder name to your one in the line below
$folder = "images";
srand( time() );
if ($directory = @opendir($folder)) {
while (($image = readdir($directory)) !== false) {
if ( eregi( '.(jpg|gif)$', $image ) ) { $images[] = $image; }
}
closedir($directory);
}
$image = $images[rand() % sizeof( $images )];
if ( eregi( '.jpg$', $image ) ) {
header( "Content-Type: image/jpeg" );
} else {
header( "Content-Type: image/gif" );
}
header( "Content-Length: " . filesize( $folder."/".$image ) );
readfile( $folder."/".$image );
?>[/code]

Can anybody detect what's wrong with this code? Note that the code didn't say anything about needing a MySQL database (which I don't have; I'm on a free hosting account).

If you must see the file which I've placed this code into, [url=http://free.hostultra.com/~halotrilogy/rotate.php]here it is[/url].

Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/28684-php-image-rotator-help/
Share on other sites

Does your hosting support GD Library? And if so, make sure that it has support for the image type you're using.

Upload a file to your host and call it info.php....with the following code:

[code]<?php

phpinfo();

?>[/code]

Then bring up that page in your browser and check for GD Library.
I've saved the code like you told me to do, but I didn't see anything about GD Library... if you want to double-check, [url=http://free.hostultra.com/~halotrilogy/info.php]here's the link[/url].

PS: The code author said you only needed PHP, and nothing else.
The code posted doesnt need the GD lib. and pretty sure his host doesnt support it ><.

Just of curiosity where'd that code come from?  It looks familiar, not sure why though...

Edit:

Hmm just tested the posted script on my local server... Worked perfect.  On the page you posted a link to some javascript tag is appearing and I think thats messin with your headers and makin it output the page as text... Does your webhost automatically append that script to everypage?
[quote author=corbin link=topic=116528.msg474823#msg474823 date=1164677262]
Edit:

Hmm just tested the posted script on my local server... Worked perfect.  On the page you posted a link to some javascript tag is appearing and I think thats messin with your headers and makin it output the page as text... Does your webhost automatically append that script to everypage?
[/quote]

Noticed the same thing. A lot of free hosts do this. Probably a popup/ad being called via Javascript.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.