How to sort images by date in this PHP script?

  • Thread starter Thread starter JR Polidario
  • Start date Start date
J

JR Polidario

Guest
I don't have any background in PHP, but I just wanted to sort the images in this script I found on the net by date. I am currently building a website and I want to put this script in the homepage to show the latest images. Any reply would be much appreciated. Thank you!


<?php
/*
Author: ricocheting.com
Creation Date: 5/11/2004
Last Update: 1/13/2008
Current Version: 1.2.1

Copyright 2004 ricocheting.com
*/


/*
This script is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/



// max image width or height allowed for thumbnail
$config['size'] = 400;

// jpeg thumbnail image quality
$config['imagequality'] = 70;

// rows of images per page
$config['rows'] = 10;

// columns of images per page
$config['cols'] = 1;

// max page numbers to show at once (so if you have 100 pages, it won't show links to all 100 at once)
$config['maxShow'] = 10;

// folder where full size images are stored (include trailing slash)
$config['fulls'] = "images/";

// folder where thumbnails are to be created (include trailing slash)
$config['thumbs'] = "thumbs/";




#-#############################################
# desc: prints out html for the table and the images found in directory
function PrintThumbs(){
global $config;


// full directory error check
if (!file_exists($config['fulls'])) {
Oops("Fullsize image directory <b>$config[fulls]</b> does not exist.");
}

// thumb directory error check
if (!file_exists($config['thumbs'])) {
if (!@mkdir($config['thumbs'], 0755)) {
Oops("Thumbnail image directory <b>$config[thumbs]</b> does not exist and can not be created. Check directory write permissions.");
}
}

// get the list of all the fullsize images
$imagelist = GetFileList($config['fulls']);

// number of and which images on current page
$config['start'] = ($config['page']*$config['cols']*$config['rows']);
$config['max'] = ( ($config['page']*$config['cols']*$config['rows']) + ($config['cols']*$config['rows']) );
if($config['max'] > count($imagelist)){$config['max']=count($imagelist);}
if($config['start'] > count($imagelist)){$config['start']=0;}


// start table
echo '<table border="0" cellpadding="0" cellspacing="0" align="center" class="gallery">';
echo "<tr>\n<td colspan=\"$config[cols]\" class=\"entries\">";

// "showing results"
if ($config['max'] == "0"){echo "Showing results <b>0 - 0</b> of <b>0</b></td></tr>\n";}
else{echo "Showing results <b>".($config['start']+1)." - $config[max]</b> of <b>".count($imagelist)."</b> entries</td>\n</tr>\n\n";}


$column_counter = 1;

// start row
echo "<tr>\n";

// for the images on the page
for($i=$config['start']; $i<$config['max']; $i++){

$thumb_image = $config['thumbs'].$imagelist[$i];
$thumb_exists = file_exists($thumb_image);

// create thumb if not exist
if(!$thumb_exists){
set_time_limit(30);
if(!($thumb_exists = ResizeImageUsingGD("$config[fulls]$imagelist[$i]", $thumb_image, $config['size']))){
Oops("Creating Thumbnail image of <strong>$config[fulls]$imagelist[$i]</strong> failed. Possible directory write permission errors.");
}
}

$imagelist[$i] = rawurlencode($imagelist[$i]);


#########################################################
# print out the image and link to the page
#########################################################
echo '<td>';
echo '<a href="'. $config['fulls'].$imagelist[$i] .'" title="'. $imagelist[$i] .'" target="_blank">';
echo '<img src="'. $config['thumbs'].$imagelist[$i] .'" alt="'. $imagelist[$i] .'">';
echo '</a>';
echo '</td>'."\n";
#########################################################


//if the max columns is reached, start new col
if(($column_counter == $config['cols']) && ($i+1 != $config['max'])){
echo "</tr>\n\n<tr><td colspan=\"$config[cols]\" class=\"spacer\"></td></tr>\n\n<tr>\n";
$column_counter=0;
}
$column_counter++;
}//for(images on the page)


// if there are no images found
if($config['start'] == $config['max']){
echo "<td colspan=\"$config[cols]\" class=\"entries\">No Entries found</td>\n";
}

// if there are empty "boxes" at the end of the row (ie; last page)
elseif($column_counter != $config['cols']+1){
echo "<td colspan=\"".($config['cols']-$column_counter+1)."\">*</td>\n";
}

// end row
echo "</tr>\n\n";
 
Back
Top