Jump to content

PHP image rotator help


john010117
 Share

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
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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.