Script 11.6 View Uploads Plus

Read all image files from the uploads directory and create an image gallery with thumbnails and image meta data. Adding the file size and date image was uploaded. When you click on a gallery preview, a new window will open with the full sized image.

Output

Click on a preview to view it fullsize in a separate window.

Source
<p>Click on a preview to view it fullsize in a separate window.</p>
<div class="thumb-gallery">
<?php # Script 11.6 - images.php
// This script lists the images in the uploads directory.
// This version now shows each image's file size and uploaded date and time.

// Set the default timezone:
date_default_timezone_set ('America/New_York');

$dir = UPLOAD_DIR; // Define the directory to view.

$files = scandir($dir); // Read all the images into an array.

// Display each image caption as a link to the JavaScript function:
foreach ($files as $image) {

	// Ignore system files starting with a period and any image with _th suffix
	if(substr($image, 0, 1) != '.' && substr(substr($image, 0,strrpos($image,'.')),-3) != THUMB_SUFFIX) { 
		// Get the image's size in pixels:
		$image_size = getimagesize("$dir/$image");
		
		// Calculate the image's size in kilobytes:
		$file_size = round ( (filesize ("$dir/$image")) / 1024) . "kb";
		
		// Determine the image's upload date and time:
		$image_date = date("F d, Y H:i:s", filemtime("$dir/$image"));
		
		// Make the image's name URL-safe:
		$image_name = urlencode($image);

		// Print the information:
		echo "<a class='gallery-item' href=\"javascript:create_window('$image_name',$image_size[0],$image_size[1])\">".getThumbnail($image)."<p class='image-meta'>$image<br /><span class='image-size'>Size $file_size</span><br /><span class='image-date'>$image_date</span></p></a>\n";
	}	  
} // End of the foreach loop.
?>
</div>