PHP (?) Help

Discussion in 'Web Design and Development (archive)' started by Wes, Mar 7, 2004.

  1. Wes
    macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #1
    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?
    [​IMG] [​IMG] [​IMG]
     
  2. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
    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.
     
  3. Wes
    thread starter macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #3
    Thanks for the quick reply, here are all the controls I have.
     

    Attached Files:

  4. Moderator emeritus

    Rower_CPU

    Joined:
    Oct 5, 2001
    Location:
    San Diego, CA
    #4
    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.
     
  5. macrumors 6502a

    sonofslim

    Joined:
    Jun 6, 2003
    #5
    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.
     
  6. Moderator emeritus

    Rower_CPU

    Joined:
    Oct 5, 2001
    Location:
    San Diego, CA
    #6
    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.
     
  7. Wes
    thread starter macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #7
    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.
     
  8. Moderator emeritus

    Rower_CPU

    Joined:
    Oct 5, 2001
    Location:
    San Diego, CA
    #8
    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...
     
  9. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #9
    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: $!";
     
  10. Wes
    thread starter macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #10
    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).
     

Share This Page