ERROR!
No directory set
"; return ; }
if ( empty( $row ) ) { echo " ERROR!
No column quantity set
"; return ; }
if ( empty( $th_width ) ) { echo " ERROR!
No thumbnail maximum width set
"; return ; }
if ( empty( $th_height ) ) { echo " ERROR!
No thumbnail maximum height set
"; return ; }
if ( $caption < '0' || $caption > '3' ) { echo " ERROR!
No caption option set or is out of range
"; return ; }
if ( $link < '0' || $link > '1' ) { echo " ERROR!
No link option set or is out of range
"; return ; }
// Start the table
echo "\n";
// The array that will store the files
$files = array();
// Read the contents of the directory
$read = $directory;
$mydirectory = opendir( $read );
while(($item = readdir( $mydirectory )) !== FALSE)
{
// If thumbnails not being used
if ( $prefix == '0' ) {
// Ignore text files
if(substr($item, -3 ) !="txt" ){
// Ignore items - sent from main code in $ignore_array
if( !in_array( $item, $ignore_array ) && is_file( "$read/$item" ))
// Build the array of images
$files[]=$item;
}}
// If thumbnails being used build the array of thumbnails only
else {
if ((substr( $item, 0, 3 ) == $prefix ) && is_file( "$read/$item" ))
// Build the array of images
$files[]=$item; }
}
closedir( $mydirectory );
// Count the number of files
$indexCount = count( $files );
// Setup the table layout
$column=1;
// Loop through the array adding the images
for ( $i=0; $i<$indexCount; $i++ )
{
// If the column value is one add a table row tag
if ( $column == 1 )
{
echo "";
}
// Strip the extension from the file name for use in the table
$file_name[$i]=substr( $files[$i], 0, -4 );
// Find longest side and use that for the image size in the table
$size=getimagesize( $read.'/'.$files[$i] );
if ( $size[1] > $size[0] ){ $th_largest = "height=\"".$th_height."\""; }
else { $th_largest = "width=\"".$th_width."\"";}
// Setup the image caption
switch ( $caption ) {
case "0":
$caption_text = "";
break;
case "1":
$caption_text = $file_name[$i];
break;
case "2":
$caption_text = exif( $read."/".$files[$i] );
break;
case "3":
$caption_text = upload_time( $read."/".$files[$i] );
break;
default:
$caption_text = "";
break;
}
// Set the cell width - all equal
$td_width = 100/( $row - 1 );
// Add a link to a larger image if set to 1
if ( $link == '1' ){
// Remove the prefix from the image for the link to full size image
if ( empty($prefix)){ $link_file = $files[$i]; }
else {$link_file = substr_replace( $files[$i], "", 0, 3 );}
// Put the images into a table cell with the image caption underneath - If link set create a link to a larger image
echo "![\"".$files[$i]."\"](\"".$read."/".$files[$i]."\") ".$caption_text." | \n";
}
else {
// Put the images into a table cell with the image caption underneath
echo "![\"".$files[$i]."\"](\"".$read."/".$prefix.$files[$i]."\") ".$caption_text." | \n";
}
// Add 1 to the column variable
$column++;
// End the row if the images reach the target number and set column variable back to 1
if ( $column == $row )
{
echo "
\n";
$column=1;
}
// End the loop to generate the table
}
echo "
\n";
}
//****************************************************
// **** Function to read the EXIF data for the taken date ****
//****************************************************
function exif( $image ){
// Check to se if the EXIF function is installed
if( !function_exists(exif_read_data)){ echo " ERROR!
EXIF function not enabled on this server
"; exit;}
else {
// EXIF only works with jpg or TIFF - so if not a jpg return to avoid displaying an error
$extension = pathinfo( $image );
$extension = strtolower( $extension['extension'] );
if ( $extension == 'jpg' || $extension == 'jpeg' ){
// Read the image exif data
$exif = exif_read_data($image);
// If the is no date for when the photo was taken in the EXIF data
if ( empty ( $exif['DateTimeOriginal'] )){ return "No date in photo EXIF"; }
// If the is a date and time for when the photo was taken ( MAY NEED TO CHANGE THE FORMATTING DEPENDING ON THE CAMERA MAKE )
$date = str_replace(' ', ':', $exif['DateTimeOriginal']);
$date = explode(':', $date);
$date = date('D jS \of F Y H:i:s', mktime( $date[3],$date[4],$date[5],$date[1],$date[2],$date[0] ));
return $date;
}
else {
return "EXIF image data not supported";
}
}
}
//********************************************
// **** Function to read the image uploaded time ****
//********************************************
function upload_time( $image ){
// Get the time the file was created on the server
$time = filemtime( "$image" );
// Formate the time
$time = date('D jS \of F Y H:i:s', $time);
return $time;
}
// Setup the size to display the image keeping the aspect ratio
function image_size ( $image, $max_width, $max_height ){
$size = getImageSize( $image );
// Resize image to fit the page better
$height = $size[1];
$width = $size[0];
$width_ratio = ( $size[0] / $max_width );
$height_ratio = ( $size[1] / $max_height );
// Resize by the longest side
// Thumbnail
if( $width_ratio >= $height_ratio ) {
$ratio = $width_ratio; }
else {
$ratio = $height_ratio; }
$width = round( $size[0] / $ratio );
$height = round( $size[1] / $ratio );
return "height=\"".$height."\" width=\"".$width."\"";
}
?>
Index of images
Our photo gallery
ERROR!
Press back on your browser to try again
";
// Read the image name and folder
$folder = $_GET['F'];
$image = $_GET['I'];
// Some error checking
if( empty( $folder ) || empty( $image )){ echo $error_message; exit; }
// Remove unwanted characters from the folder and image names
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i';
$folder = preg_replace($pattern, "", $folder);
$image = preg_replace($pattern, "", $image);
// Build the folder and name back into a path
$path = $folder."/".$image;
// Read the passed directory and build an array for error checking
$mydirectory = opendir( $folder );
while($item = readdir( $mydirectory ))
{
$files[]=$item; }
// If the image is in the folder display it else display an error
if ( in_array( $image, $files ) ) {
// Read caption file into variable
if ( $image_caption == "1" ){
$text = $path;
$text = str_replace( "jpg", "txt", $text );
$text = str_replace( "jpeg", "txt", $text );
$text = str_replace( "JPG", "txt", $text );
$text = str_replace( "png", "txt", $text );
$text = str_replace( "gif", "txt", $text );
// If the text file does not exist do not show an error
if (file_exists($text)) {
$text = stripslashes(file_get_contents( $text )) ;
$text = ucfirst( $text );
}
else $text = "";
}
else $text = "";
echo "
".$text."
Back to the index
";
}
else { echo $error_message; exit; }
}
?>
Back to the main site