Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

4409723

Suspended
Original poster
Hi,
I dabble in 3D and have an online gallery at: www.tyui.com

I like the website to be dynamic and I have made 3 loading images. The gallery loads the picture load.JPG. I have created load1.JPG and load2.JPG. I can not access the flash to change which it loads but I was wondering if it was possible to have PHP rotate the names of these pictures so that every hour, or day, the loading image changes. Here are the three images.

Anyone have a solution?
load.JPG
load1.JPG
load2.JPG
 
Seems the better option would be to use a cron job or scheduled job to rotate the filenames on the server that hosts your website. Do you have access to this server? Do they support cron (or the equivalent)? If so, you could write a small script (in shell or perl) to run, say every hour, and rotate the names of those images.

Im guessing you could do the same with a PHP page using all the file handling routines, but thats really overkill in this situation.
 
Thanks for the quick reply, here are all the controls I have.
 

Attachments

  • controls.jpg
    controls.jpg
    96.5 KB · Views: 166
Another possibility that doesn't necessitate file renaming would be to add the picture names into an array and then shuffle to order to randomly choose a new image. I do something similar on a page at work to get a series of "ad" buttons to change order. However, this will result in a new image for every refresh or new page hit.

PHP:
$picture = array("picture1", "picture2", "picture3");
shuffle($picture);
echo "$picture[0].jpg";

Or, just set up some if statements that check the time of day and select a particular image.

PHP:
$time = date("G");
if ($time > 300) {
  echo "picture1.jpg"
} elseif ($time > 600) {
  echo "picture2.jpg"
}
etc.
 
although, php's randomizer is not great. if you're not too concerned about it, it's good enough. but it won't shuffle them equally -- you're going to see some images more than others.
 
sonofslim said:
although, php's randomizer is not great. if you're not too concerned about it, it's good enough. but it won't shuffle them equally -- you're going to see some images more than others.

Is that due to the algorithm it uses, or is it just lazy?

How about double shuffling? With a small set of images it wouldn't make much difference, but with a lot it could be helpful.
 
okay guys, I've talked to a few people who know HTML and have explained the situation. The picture is inside the flash file and it looks at a config file to find the location of this file. It looks like it would easiest to just cron it.
 
Wes said:
okay guys, I've talked to a few people who know HTML and have explained the situation. The picture is inside the flash file and it looks at a config file to find the location of this file. It looks like it would easiest to just cron it.

Flash can talk to PHP files via AS, too, so you do have another option besides the cron task. It's not too tough to do...
 
Perl script.

#!/usr/bin/perl
#
# This could obviously be enhanced for better error handling, but should accomplish your task.
#Add this to a directory that is NOT web accessible (otherwise outside users could run this)
#Make sure you (owner) have execute permissions such as 740
#Set cron to run this script every hour (or as your desire)
#sample cron entry
#0 * * * * /path/to/your/script.pl > /path/to/your/script.log


#change this, note NO ending slash
$basePath = "/path/to/your/images";

rename("$basePath/load2.JPG", "$basePath/load.tmp.JPG") || die "Cannot rename load2.JPG: $!";
rename("$basePath/load1.JPG", "$basePath/load2.JPG") || die "Cannot rename load1.JPG: $!";
rename("$basePath/load.JPG", "$basePath/load1.JPG") || die "Cannot rename load.JPG: $!";
rename("$basePath/load.tmp.JPG", "$basePath/load.JPG") || die "Cannot rename load.tmp.JPG: $!";

#delete tmp
unlink("$basePath/load.tmp.JPG") || die "Cannot delete load.tmp.JPG: $!";
 
Thanks for all your help guys, Rower_CPU has set it up with cron and it's working like a dream (at 3 minute intervals).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.