Jump to content

fishbowl

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

fishbowl's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [quote author=akitchin link=topic=103935.msg414818#msg414818 date=1155438675] hopefully that patches it up. [/quote] It worked!! This is awesome. Thanks so much for all the help. :)
  2. Okay, it's still not changing the images. The new while() loop you provided didn't look different from the original while() loop, other than the "// boot out if we've reached the limit of images" section of code being removed. I also inserted the new 2 lines. Well, just for reference, this is what it looks like so far. It's still showing the same 20 images. [code]<?php function get_images_list($list_filename, $path_to_images, $number_of_images) {   // define an array of image extensions   $image_extensions = array('gif');   // initialise the return variable   $image_list = array();   // check if the list file exists   if (file_exists($list_filename))   {     // include it so that it defines an array for us (called $image_list by default)     include($list_filename);     // check if the list is less than 24 hours old     if ($image_list['timestamp'] >= (time() - 10))     {       // if it is less than 24 hours old, just drop the timestamp and return the list       unset($image_list['timestamp']);       return $image_list;     }     else     {       // if it's stale, then undo the definition the include has made       unset($image_list);     }   }   // by now it will have booted out of the function if the file's image list was useable   // therefore if we're still here, we need to create a new file list (either for the first time, or to replace the stale one)   // open the images directory   $handle = @opendir($path_to_images);   // boot out with a NULL return if the directory couldn't be opened   if ($handle === FALSE)     return NULL;   // otherwise, go through the directory   while ($filename = readdir($handle))   {     // grab a lowercase version of its extension     $extension = strtolower(substr(strrchr($filename, '.'), 1));     // if its extension is an image type, then log it     if (in_array($extension, $image_extensions))       $image_list[] = $filename;   }   // close the directory   closedir($handle); $chunks = array_chunk($image_list, $number_of_images); $image_list = $chunks[0];   // add a timestamp to the array   $image_list = array_merge($image_list, array('timestamp' => time()));   // turn the list content into something useable   $content = '<?php $image_list = '.var_export($image_list, TRUE).'; ?>';   // write the list to a file   $newfile = fopen($list_filename, 'w');   fwrite($newfile, $content);   fclose($newfile);   // kill the timestamp again   unset($image_list['timestamp']);   // return NULL if it found no images, or the image list if it did   return (empty($image_list)) ? NULL : $image_list; } $image_list = get_images_list('image_list.php', 'images/', 20); if ($image_list === NULL || empty($image_list)) {   echo 'No images could be grabbed.'; } else { foreach ($image_list AS $filename) {   echo '<img src="images/'.$filename.'" />'; } } ?>[/code]
  3. I see. Well, I edited the number of seconds in both codes, and neither changed the set of images when I refreshed after 10 seconds. I also tried manually removing the image lists, to see if it would create a new set of random images, but the same random images are pulled each time. With both codes. :-[
  4. RockingGourdon, your code has a similar timestamp line in it, and again I can't figure out how to modify it so that I don't have to wait 24 hours to test it. I tried what I did with akitchin's code, but with yours, and got the same results. So I assume that I'm doing something wrong. My only problem with your code is that I don't want to go through and rename all 2000 images to image1.gif, image2.gif, etc. Thanks for the help, though.
  5. Thanks to everyone for their responses.. this is by far the most helpful forum I've ever been on. akitchin, I tried your script, and it seems to be working. I didn't want to wait 24 hours to test it, so I took this line: [code]    // check if the list is less than 24 hours old     if ($image_list['timestamp'] >= (time() - 24*3600))[/code] and tried editing it so that it would change the images, say, every minute. I wasn't really sure how to format that (did several PHP.net/Google searches, came up empty handed), so I tried changing the "24*3600" to things like, "1*60", "60", "0", "1*1", "1". Waited about 2 minutes after each change to refresh, and the same random images came up each time. So, I'm not sure if that's a problem with the script, or if I formatted the time wrong. I do have a mysql database, as well as PHP 4.4. However, I literally know nothing about mysql coding.. I can install pre-written scripts, but I don't know how to write my own or edit any existing ones.
  6. Thanks for the help so far.. corbin, I tried the attached files, but they don't really work right. The images change with every refresh, and the number of images changes as well. Also, there's always at least one broken image, where no image name is pulled (shows up in images.txt as a string of numbers). I really don't know anything about PHP, so I have no idea what's going on in those files. I've been trying to read through online PHP manuals to figure it out, but.. more help would be appreciated. :-\
  7. I need a script that will pull 20 random images from a pool of 2000, and will keep those same random 20 images for a certain time period. For example, every day a new set of 20 random images would show up. I've found a lot of random image scripts, but with all of them, the image changes every time the page is refreshed. I don't want the images to change that often, but they do need to change periodically, without my having to go into the code and change the images manually. I'm thinking about trying to modify an existing php random image script to do the above. However, I don't really know anything about PHP, and I have no idea where to begin.
×
×
  • 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.