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]