USE AT OWN RISK
Generated: Tue Jul 31 15:22:06 2007 from imgview.php 2005/11/26 10.3 KB bytes.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Image Viewer</title> <head> <body background="cldsm.jpg"> <?php /* imgview.php AIM: To read a sub-directory of thumbs, and allow viewing of then in a table of images, paged ... If there exists a full-size image of the SAME name, minus the -t, then allow click loading of that image, into another window ... 25 November, 2005 Geoff McLane */ $g_actpage = 1; $g_type = 'a'; // get the page value, if any if (isset($_GET['page'])) { $g_actpage = $_GET['page']; } if (isset($_GET['type'])) { $g_type = $_GET['type']; } if($g_actpage < 1) $g_actpage = 1; //$thumb_folder = 'temp'; //$full_folder = 'c:/HOMEPAGE/P26/mona'; $thumb_folder = 'thumbs'; $full_folder = '.'; $inp_file = ''; $full_file = ''; $file_count = 0; $m_row_wrap = 5; // establish row WRAP $m_max_out = 15; // establish MAX images $m_pg_max = 10; // establish MAXIMUM pages to show in menu line $meol = "\r\n"; $g_filearr = array(); // store the found items here // offset in the array gathered $arr_tn = 0; $arr_ff = 1; $arr_sz = 2; $arr_tm = 3; $arr_st = 4; getfilearr (); $imgcnt = count( $g_filearr ); // this is count of images if (($imgcnt == 0) || (ordFileList_by_date() == 0) ) { print "<p>No image count, or order failed! </p>\r\n"; exit(1); } $rmi = $imgcnt % $m_max_out; $cnt = ($imgcnt - $rmi) / $m_max_out; // get PAGE count if($rmi) $cnt++; // bump one more page //echo "Got $imgcnt files rmi=$rmi pages=$cnt tot=" . ($cnt * $m_max_out) . " ap=$g_actpage<br>$meol"; $max = $m_pg_max; // normal MAXIMUM page display if($cnt < $max) $max = $cnt; if($g_actpage > $cnt) $g_actpage = $cnt; $pg = 0; $sp = 0; $rm = $g_actpage % $m_pg_max; // get remainder $sp = ($g_actpage - $rm) / $m_pg_max; // get start page //echo "Got $cnt pages max=$max rm=$rm sp=$sp... ap=$g_actpage<br>$meol"; $rmsg = 'Select Page: '; $i = 0; $pg = 1 + ($sp * $m_pg_max); $mp = $pg + $m_pg_max - 1; if($mp > $cnt) $mp = $cnt; $rng = "(Range: $pg-$mp of $cnt)"; if($pg > $m_pg_max) { $pg--; $rmsg .= $meol . '<a href="imgview.php?page=' . $pg . '">Previous</a> '; } for( $i = 0; $i < $max; $i++ ) { $pg = $i + 1 + ($sp * $m_pg_max); if($pg > $cnt) break; if( $g_type == '*' ) { $rmsg .= $meol . '<a href="imgview.php?page=' . $pg . '">' . $pg . '</a> '; } else { if( $pg == $g_actpage ) { $rmsg .= "$pg "; } else { $rmsg .= $meol . '<a href="imgview.php?page=' . $pg . '">' . $pg . '</a> '; } } } if($pg < $cnt) { $pg++; $rmsg .= $meol . '<a href="imgview.php?page=' . $pg . '">More</a> '; } if( $g_type == '*' ) { $rmsg .= 'All '; } else { $rmsg .= $meol . '<a href="imgview.php?page=' . $g_actpage . '&type=*">All</a> '; } // $rmsg .= " $rng"; $msg = $meol . '<table width="100%" border="0"><tr>'.$meol; $msg .= '<td width="30%" align="left">' . $meol; $msg .= $rmsg . $meol; $msg .= '</td><td width="30%" align="center">Click on Image to Enlarge' . $meol; $msg .= '</td><td width="30%" align="right">' . $rng . $meol; $msg .= '</td></tr></table>' . $meol; //print add_b_span($rmsg) . $meol; print add_b_span($msg) . $meol; // now to output the table of images $is = (($g_actpage - 1) * $m_max_out); print $meol . '<table width="100%" border="2">'.$meol; if ($g_type == '*') { // output ALL images for( $i = 0; $i < $imgcnt; $i++ ) { $pg = $i; if( ($i % $m_row_wrap) == 0 ) { print '<tr>' . $meol; } print '<td align="center" valign="center">' . $meol; print get_img_msg($pg) . $meol; print "</td>$meol"; if( (($i + 1) % $m_row_wrap) == 0 ) { print '</tr>' . $meol; } } if( ($i % $m_row_wrap) != 0 ) { while( ($i % $m_row_wrap) != 0 ) { print '<td align="center" valign="center">' . $meol; print "No image"; print "</td>$meol"; $i++; } print '</tr>' . $meol; } } else { // NOT ALL - output a SUBSET for( $i = 0; $i < $m_max_out; $i++ ) { // for the set of images $pg = $i + $is; if( ($i % $m_row_wrap) == 0 ) { print '<tr>' . $meol; } print '<td align="center" valign="center">' . $meol; print get_img_msg($pg) . $meol; print "</td>$meol"; if( (($i + 1) % $m_row_wrap) == 0 ) { print '</tr>' . $meol; } } } print '</table>' . $meol; print '<p align="center"><a href="index.htm">Mona Index</a></p>' . $meol; // ############################ // helper functions // ############################ function get_img_msg( $in_num ) { global $imgcnt, $g_filearr; global $arr_tn, $arr_ff, $arr_sz, $arr_tm, $arr_st; global $meol; $rmsg = ''; $num = $in_num + 1; if($in_num < $imgcnt) { for( $i = 0; $i < $imgcnt; $i++ ) { $arr = $g_filearr[$i]; if( $arr[$arr_st] == $num ) break; // found our ORDER number } if( $i < $imgcnt ) { $arr = $g_filearr[$i]; $ffl = strlen($arr[$arr_ff]); if($ffl) { // we have a FULL file $fn = $arr[$arr_ff]; $rmsg .= '<a target="_blank" href="' . $arr[$arr_ff] . '">' . $meol; } else { $fn = $arr[$arr_tn]; } $parts = split("/",$fn); $pc = count($parts); $alt = 'File is ' . $parts[$pc-1]; // last part is FILE NAME $alt .= ' ' . date("F d Y H:i:s.", $arr[$arr_tm]); $alt .= ' ' . $arr[$arr_sz] . ' bytes'; $rmsg .= '<img src="' . $arr[$arr_tn] . '" alt="' . $alt . '" />'; if($ffl) $rmsg .= $meol . '</a>'; } } if( strlen($rmsg) == 0 ) { $rmsg .= "No image"; } return $rmsg; } function get_img_msg_no_sort( $num ) { global $imgcnt, $g_filearr; global $arr_tn, $arr_ff, $arr_sz, $arr_tm, $arr_st; $rmsg = ''; if($num < $imgcnt) { $arr = $g_filearr[$num]; $ffl = strlen($arr[$arr_ff]); if($ffl) { // we have a FULL file $alt = 'File is ' . $arr[$arr_ff]; $rmsg .= '<a target="_blank" href="' . $arr[$arr_ff] . '">'; } else { $alt = 'File is ' . $arr[$arr_tn]; } $alt .= ' ' . date("F d Y H:i:s.", $arr[$arr_tm]); $alt .= ' ' . $arr[$arr_sz] . ' bytes'; $rmsg .= '<img src="' . $arr[$arr_tn] . '" alt="' . $alt . '" />'; if($ffl) $rmsg .= '</a>'; } else { $rmsg .= "No image"; } return $rmsg; } function add_b_span ( $msg ) { return '<span style="background-color: #eeeeff;"><font style="color: black;">'. $msg . '</font></span>'; } function add_b_span2 ( $msg ) { return '<span style="background-color: #0066cc;"><font style="color:#ffffff; font-size:small;">'. $msg.'</font></span>'; } function ProcessFile ( $in_file, $f_folder, $f_file ) { global $meol; global $g_filearr; $ff = $f_folder . '/' . $f_file; $arr = array(); $arr[] = $in_file; // store the THUMB file name = $arr_tn = 0; if( file_exists( $ff ) ) { //echo "Found full file $ff ...<br>$meol"; $arr[] = $ff; // store the FULL file name = $arr_ff = 1; $arr[] = filesize($ff); // add file size = $arr_sz = 2; $arr[] = filemtime($ff); // and time = $arr_tm = 3; } else { //echo "NO full file $ff found! ...<br>$meol"; $arr[] = ''; // signal NO full file found $arr[] = filesize($in_file); $arr[] = filemtime($in_file); } $arr[] = 0; // no SORT ORDER yet = $arr_st = 4; $g_filearr[] = $arr; // store this file information... } function IsMYFile( $in_file ) { // this is a VERY SPECIALISED filter global $full_file; // where to STORE the FULL FILE NAME global $meol; // separate file name and extention $parts = split("\.", $in_file); $pc = count($parts); if( $pc > 1 ) { $file_ext = $parts[$pc-1]; // last part is FILE NAME $filea = array_slice($parts,0,$pc-1); $file_tit = implode( ".", $filea ); } else { $file_tit = $in_file; $file_ext = ""; } // (a) I only want '.jpg' files if( strtolower( $file_ext ) != 'jpg' ) { echo "IsMYFile: FAILED TEST 1 - not a jpeg file ...<br>$meol"; return 0; // failed test 1 } // (b) File name length MUST be greater than 2 $fnl = strlen($file_tit); if( $fnl <= 2 ) { echo "IsMYFile: FAILED TEST 2 - does not have length ...<br>$meol"; return 0; // failed length test 2 } // (c) The file name MUST end in '-t' if( substr($file_tit, -2, 2) != '-t' ) { echo "IsMYFile: FAILED TEST 3 - title $file_tit missing '-t' ...<br>$meol"; return 0; // failed test 3 } // get name, without the '-t' $ffn = substr($file_tit, 0, ($fnl - 2)); $full_file = $ffn . '.jpg'; return 1; } function getfilearr () { global $thumb_folder, $full_folder, $full_file; global $file_count; $mydir = opendir($thumb_folder) ; if( !$mydir ) { echo "ERROR: Can not OPEN directory [$thumb_folder] ... aborting ... <br>$meol"; return 0; } while($fn = readdir($mydir)) //scan through the whole directory { if( !(($fn == '.') || ($fn == '..')) ) { $inp_file = $thumb_folder . '/' . $fn; //echo "Processing file $inp_file ...<br>$meol"; if( IsMYFile( $fn ) ) { $file_count++; ProcessFile($inp_file, $full_folder, $full_file); } } } closedir($mydir); return $file_count; } function ordFileList_by_date () { global $g_filearr; // this is the LIST of found files do display global $arr_tm, $arr_st; $imx = count( $g_filearr ); // get COUNT of FOUND ITEMS - full list of arrays if($imx == 0) { return 0; } $imx2 = $imx; // copy count $got_ord = 1; // SORT the array of files, per their FILETIME // iterate, finding the most recent, non-ordered, each time while($imx2) { // set order to N, N-1, N-2, ..., 1 ... note 1 is last $ft = 0; // start with zero time $idx = $imx; for($i = 0; $i < $imx; $i++) { $arr = $g_filearr[$i]; // extract array if( $arr[$arr_st] == 0 ) { // if NO SORT if( $arr[$arr_tm] > $ft ) { // if later $ft = $arr[$arr_tm]; // get it, $idx = $i; // keeping the index to it } // check each FILETIME ... } } if( $idx < $imx ) { // found highest, latest, NOT previously ORDERED ... (nnn ... 1) $arr = $g_filearr[$idx]; // extract array, of file things $arr[$arr_st] = $imx2; // set ORDER - N to 1 $g_filearr[$idx] = $arr; // replace array, with value update // print "<p>Set order $arr[3]!</p>\r\n"; } else { print "<p>No order! Internal error, or filetime is ZERO!</p>\r\n"; $got_ord = 0; } $imx2--; } return $got_ord; // 1 = success - should NEVER be zero } ?> </body> </html> <!-- P26.2005.11.25 - geoffmclane.com/mona -->