1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Easiest Solution For Auto Updating Images Using My Current PHP Script?

Discussion in 'PHP & Perl' started by ycfme, Dec 18, 2010.

  1. ycfme

    ycfme Power Member

    Joined:
    Mar 24, 2010
    Messages:
    779
    Likes Received:
    65
    Hey Guys,

    So I actually have that same script as this site
    HTML:
    hxxp://onlinebikinibabes.com 
    . However, it does not automatically update fresh images on it's own. I'd like to place images in a queue, which would then in turn update fresh images several times daily.

    Any idea what kind of script/code that would do this?

    I'm not a coder or anything so the simpler the better.

    Thanks!:hello:
     
  2. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    Are you looking to add new images each day, or just change them around so they appear in different places?
     
  3. ycfme

    ycfme Power Member

    Joined:
    Mar 24, 2010
    Messages:
    779
    Likes Received:
    65
    Hi, Thanks for responding.

    I'd like to add "new images" Seeing that I have over 20k images i'm sure even if the script fetched images by groups of 10-20 images each day i would still have plenty of room for shuffling images around.

    I would prefer to not have images reappearing, before cycling throughout the entire folder of images.

    Any ideas?

     
  4. f0rked

    f0rked Registered Member

    Joined:
    Jan 25, 2009
    Messages:
    71
    Likes Received:
    64
    If you have access to cron, it would be the most efficient.
     
  5. coderjeff

    coderjeff Junior Member

    Joined:
    Nov 20, 2007
    Messages:
    130
    Likes Received:
    26
    Location:
    USA
    Been discussing this by PM, but will post code here in case anyone else finds it useful.

    Create a new folder to hold your images and set the permission to 777 so the images can be deleted after they are copied to the other folder.

    Code:
    <?php
    $in_dir = 'queue/';  // From directory
    $out_dir = 'images/'; // To directory
    $indir = dir($in_dir);
    $dirlist = array();
    while ($file = $indir->read()) { // read filenames
      if(0 != strpos($file, '.jpg')) // if filename has .jpg in it
          $dirlist[] = $file;        // add to array
    }
    $indir->close();
    $howmany = rand(10,20);  // move from 10 to 20
    $images = array_slice($dirlist, 0, $howmany);
    foreach ($images as $curr) {
      if (copy("$in_dir$curr","$out_dir/$curr")) {
        unlink("$in_dir/$curr");
        }
      }
    You can change the number of images to be copied each time on the line that sets $howmany. Here I have it randomly choosing between 10 and 20. It should copy the images in the same order that they were put into the folder.
     
    • Thanks Thanks x 1
  6. mr285

    mr285 Newbie

    Joined:
    Jul 21, 2010
    Messages:
    16
    Likes Received:
    4
    Sorry 4 the hijack but how did u get the images to begin with? Scrape the net?
     
  7. ycfme

    ycfme Power Member

    Joined:
    Mar 24, 2010
    Messages:
    779
    Likes Received:
    65
    No prob... Let's just say I love chicks :p

    There are TONS of sites/forums etc. out there for images. You can even take your own (I do on occasion...)