PDA

View Full Version : PHP (?) Help


Wes
Mar 7, 2004, 10:41 AM
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?
http://wesley.wsgurus.com/imagevue/load.JPG http://wesley.wsgurus.com/imagevue/load1.JPG http://wesley.wsgurus.com/imagevue/load2.JPG

jeremy.king
Mar 7, 2004, 10:47 AM
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.

Wes
Mar 7, 2004, 11:01 AM
Thanks for the quick reply, here are all the controls I have.

Rower_CPU
Mar 7, 2004, 01:29 PM
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.

$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.

$time = date("G");
if ($time > 300) {
echo "picture1.jpg"
} elseif ($time > 600) {
echo "picture2.jpg"
}
etc.

sonofslim
Mar 7, 2004, 01:40 PM
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.

Rower_CPU
Mar 7, 2004, 01:45 PM
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.

Wes
Mar 7, 2004, 01:56 PM
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.

Rower_CPU
Mar 7, 2004, 02:06 PM
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...

jeremy.king
Mar 8, 2004, 09:11 AM
#!/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: $!";

Wes
Mar 8, 2004, 10:02 AM
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).