imagesa9.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:05 2007 from imagesa9.php 2005/08/05 11.5 KB bytes.

<html>

<head>
<meta http-equiv="Content-Language" content="en-au">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="refresh" content="90;url=imagesa9.php">

<title>Image 160x120 Index 2</title>

</head>

<body background="images/lotus01.jpg">

<h1 align="center"><b>Image 160x120 Index 2</b></h1>

<p align="center"><span style="background-color: #FFFFFF">|* <a href="index.html">index</a>
 *|</span></p>

<?php 
//$m_folder = 'images/.';
$m_folder = 'c:/HOMEPAGE/russ4/images/.';
$m_addtab = 0; // output, more a debug big list of files, and folders found
$m_mostcnt = 0;
$m_mostnam = ' ';
$m_mostarr = array();
$m_msg = ' ';
$m_type = 'a'; // set the DAY, type of file to find, list ...
$m_add_txt = 1;

function getBlkSz( $sz ) {
   $blk = 4096;
   $bcnt = $sz / $blk;
   settype($bcnt,"int");
   if( $sz % $blk ) $bcnt++;
   if( $bcnt == 0 ) $bcnt++; // make zero a 1
   return ($bcnt * $blk);
}

function getSizeStr( $insz ) {
 $sz = getBlkSz( $insz );
 $ss = "$sz";
 if($sz < 10) {
 $ss .= ' B';
 } elseif($sz < 1024) {
 $ss .= ' B';
 } elseif($sz < (1024*1024)) {
 $sk = ($sz / 1024) * 10;
 settype($sk,"int");
 $sk = $sk / 10;
 $ss = "$sk";
 $ss .= ' KB';
 } elseif($sz < (1024*1024*1024)) {
 $sk = ($sz / (1024*1024)) * 10;
 settype($sk,"int");
 $sk = $sk / 10;
 $ss = "$sk";
 $ss .= ' MB';
 } else {
 $sk = ($sz / (1024*1024*1024)) * 10;
 settype($sk,"int");
 $sk = $sk / 10;
 $ss = "$sk";
 $ss .= ' GB';
 }
 return $ss;
}

function TranslatePerm( $in_Perms ) {
 $sP = ' ';

 if(($in_Perms & 0xC000) == 0xC000) // Socket
 $sP = 's';
 elseif(($in_Perms & 0xA000) == 0xA000) // Symbolic Link
 $sP = 'l';
 elseif(($in_Perms & 0x8000) == 0x8000) // Regular
 $sP = '&minus;';
 elseif(($in_Perms & 0x6000) == 0x6000) // Block special
 $sP = 'b';
 elseif(($in_Perms & 0x4000) == 0x4000) // Directory
 $sP = 'd';
 elseif(($in_Perms & 0x2000) == 0x2000) // Character special
 $sP = 'c';
 elseif(($in_Perms & 0x1000) == 0x1000) // FIFO pipe
 $sP = 'p';
 else // UNKNOWN
 $sP = 'u';

 // owner
 $sP .= (($in_Perms & 0x0100) ? 'r' : '&minus;') .
 (($in_Perms & 0x0080) ? 'w' : '&minus;') .
 (($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) :
 (($in_Perms & 0x0800) ? 'S' : '&minus;'));

 // group
 $sP .= (($in_Perms & 0x0020) ? 'r' : '&minus;') .
 (($in_Perms & 0x0010) ? 'w' : '&minus;') .
 (($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x' ) :
 (($in_Perms & 0x0400) ? 'S' : '&minus;'));

 // world
 $sP .= (($in_Perms & 0x0004) ? 'r' : '&minus;') .
 (($in_Perms & 0x0002) ? 'w' : '&minus;') .
 (($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x' ) :
 (($in_Perms & 0x0200) ? 'T' : '&minus;'));
 return $sP;
}

// $file = lstat("/bin/bash");
// echo TranslatePerm($file['mode']);

// function isMyFile( $file, $cls )
// file name of form 'temp' + single-letter [a,b,c...] + number 0000 form + '.jpg'
// *******************************************************************************
function isMyFile( $file, $cls ) {
   $ln = strlen($file);
   if($ln >= (4+1+4+1+3)) {
   $pos = strrpos($file,".");
   $exten = substr($file,($pos+1));
   if( ( substr($file,-4,4) == '.jpg' ) &&
   ( substr($file,0,4) == 'temp' ) ) {
   if( $cls == substr($file,4,1) ) { // get 'a', 'b', 'c', ... , 's' (sunset 60)
   // got our TYPE
   return 1;
   } // got class, day, set
   } // got 'temp' part
   } // get length
   return 0;
}


function outOrderList ( $imx, $got_ord, $m_mostarr, $row_wrap, $max_out ) {
   global $m_add_txt;
   $imx2 = $imx; // copy count
   $td_wid = ' <td width="160">';
   $img_wid = ' width="160" height="120"';
   if( $got_ord ) {
   $mx_ord = $max_out;
   $got_ord = 0;
 print "<div align=\"center\">\r\n";
   print "<center>\r\n";
   print "<table border=\"2\" cellpadding=\"2\" cellspacing=\"2\" width=\"480\">\r\n";
   while($imx2) {
   for($i = 0; $i < $imx; $i++) {
   $arr = $m_mostarr[$i]; // extract array
   if( $arr[3] == $imx2 ) { // found current order
   $date = date("F d Y H:i:s.", $arr[1]);
   $a_msg = '';
   $a_msg .= $arr[0] . ' ';
   $a_msg .= $date . ' '; // = date("F d Y H:i:s.", $arr[1]) . ' ';
   $a_msg .= " $arr[2]";
   $a_msg .= " $arr[3]";

   $m_msg = '';
   if(($got_ord % $row_wrap) == 0) {
   $m_msg .= " <tr>";
   }
   $m_msg .= $td_wid;
   $m_msg .= "<img src=\"$arr[4]\" alt=\"$a_msg\"";
   $m_msg .= $img_wid; // like = " width=\"160\" height=\"120\""
   $m_msg .= ">";
   if ($m_add_txt) {
   $m_msg .= "<br><font size=\"-2\">";
   $m_msg .= $arr[0]; // like, temp?nnnn.jpg
   $m_msg .= ' ' . date("H:i:s", $arr[1]);
   //$m_msg .= " $date";
   //$m_msg .= $a_msg;
   $m_msg .= "</font>";
   }
   $m_msg .= " </td>";
   $got_ord++;
   if(($got_ord % $row_wrap) == 0) {
   $m_msg .= " </tr>";
   }
   print "$m_msg\r\n";
   break;
   }
   }
   $imx2--;
   if($got_ord >= $mx_ord) {
   break;
   }
   }

   // fill in any missing SET-OF-?????
   if( $got_ord % $row_wrap ) {
   $m_msg = $td_wid; // = say ' <td width="160">';
   $m_msg .= 'no image';
   $m_msg .= ' </td>';
   $got_ord++;
   if(($got_ord % $row_wrap) == 0) {
   $m_msg .= " </tr>";
   }
   print "$m_msg\r\n";
   }
   print "</table>\n";
   print "</center>\r\n";
   print "</div>\r\n";
   }
}


function getDirList2 ($dirName, $dep, $mostrec, $mostnam, $mostcnt, $mostarr, $add_tab, $typ ) { 
 $fdrgif = 'folder.gif';
 $filgif = 'file.gif';
 $d = dir($dirName); // note, with '/.' added
 // build up a LIST of directories, and files, in this folder
 while($entry = $d->read()) {
   //$locpath = $dirName."/".$entry;
 $locpath = substr($dirName,0,(strlen($dirName)-1)).$entry;
 if ($entry != "." && $entry != "..") {
   //$type = filetype($locpath);
 //$size = filesize($locpath);
 if (is_dir($locpath)) {
   //getDirList($locpath, ($dep + 1)); 
 //echo "<img src=\"folder.gif\"> ".$entry." DIR $type <br>";
 $dirlist[] = $entry;
   } else {
   //echo "<img src=\"file.gif\"> ".$entry." $size bytes $type<br>\n"; 
 $fillist[] = $entry;
 } 
 } 
 } 
 $d->close();
 $totb = 0; 

 if( $add_tab ) {
   echo "root=".getcwd()."/.<br>\n";
   echo "<table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n";
   echo "<tr><td>\n";
   echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n";
   echo "<tr bgcolor=\"#EFEFEF\"><td>img</td><td>name</td><td>size</td>";
   echo "<td>date/time</td><td>permissions</td></tr>\n";
 }

 if (isset($dirlist)) {
 asort($dirlist);
 foreach ($dirlist as $dir) {
 // $locpath = $dirName."/".$dir;
 $locpath = substr($dirName,0,(strlen($dirName)-1)).$dir;
 $stats = stat($locpath);
 $size = $stats['size'];
 // $totb += $size;
 $totb += getBlkSz($size);
 $filst = lstat($locpath);
 $perm = TranslatePerm($filst['mode']);
   if( $add_tab ) {
   echo "<tr><td><img src=\"" . $fdrgif;
   echo "\"></td><td>".$dir;
   echo "</td>";
   echo "<td>$size</td>";
   echo "<td><b>DIR</b></td>";
   echo "<td>$perm</td>";
   echo "</tr>\n";
   }
 }
 }

 if (isset($fillist)) {
 asort($fillist);
 foreach ($fillist as $fil) {
 // $locpath = $dirName."/".$fil; // note: dir name ends with '/.', guaranteed!!!
 $locpath = substr($dirName,0,(strlen($dirName)-1)).$fil;
 $size = filesize($locpath);
 // $totb += $size;
 $totb += getBlkSz($size);
   $filtm = filemtime($locpath);
   // if( isMyFile( $fil, 's' ) ) {
   if( isMyFile( $fil, $typ ) ) {
   if( $filtm > $mostrec ) {
   $mostrec = $filtm;
   //$mostnam = $locpath;
   $mostnam = $fil;
   }
   $arr = array();
   //$arr[] = $locpath;
   $arr[] = $fil; // 'temp' + class + number[1-9999] + '.jpg'
   $arr[] = $filtm; // keep the file time
   $arr[] = $size; // keep file size
   $arr[] = 0; // sort order
   $arr[] = $locpath; // keep WHOLE (relative) name
   // ==================================================
   $mostarr[] = $arr; // keep the files that MATCH class
   $mostcnt++; // bump COUNT
   }

 $date = date ("F d Y H:i:s.", $filtm);
 // $date = date ("F d Y H:i:s.", filemtime($locpath));
 $filst = lstat($locpath);
 $perm = TranslatePerm($filst['mode']);
   if( $add_tab ){
   echo "<tr><td><img src=\"" . $filgif . "\"></td><td>".$fil."</td>\n";
   echo "<td>$size (". getSizeStr($size) . ")</td>\n";
   echo "<td>$date</td>\n";
   echo "<td>$perm</td></tr>\n";
   }
 }
 }
 
 if( $add_tab ) {
   // echo "<tr><td><b>Total ".$totb." bytes</b></td></tr>";
   echo "<tr bgcolor=\"#EFEFEF\"><td>img</td>";
   echo "<td><b>Total</b></td>";
   echo "<td><b>".$totb." (". getSizeStr( $totb ) .")</b></td>";
   echo "<td><b> - </b></td>";
   echo "<td>perm</td>";
   echo "</tr>\n";
   echo "</table>\n";
   echo "</td></tr>\n";
   echo "</table>\n";
 }
} // end func getDirList2 ($dir, $dep, $rec, $nam, $cnt, $arr, $tab, $typ )



// *****************************************************************************************
// do the action
getDirList2 ($m_folder, 0, &$m_mostrec, &$m_mostnam, &$m_mostcnt,
 &$m_mostarr, $m_addtab, $m_type );
// *****************************************************************************************
// did we collect the files we need ...
if( $m_mostrec > 0 ) {
   $imx = count( $m_mostarr ); // get COUNT of FOUND ITEMS - full list of arrays
   $imx2 = $imx; // copy count
   $got_ord = 1;
   // SORT the array of files, per their FILETIME
   // interate, 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 = $m_mostarr[$i]; // extract array
   if( $arr[3] == 0 ) {
   if( $arr[1] > $ft ) { // if later
   $ft = $arr[1]; // get it,
   $idx = $i;   // keeping the index to it
   }
   }
   }
   if( $idx < $imx ) {
   // found highest, latest
   $arr = $m_mostarr[$idx]; // extract array, of file things
   $arr[3] = $imx2; // set ORDER
   $m_mostarr[$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--;
   }

//   if( $imx < 9 ) { // if a VERY SHORT list
//   $m_msg = '<p>';
//   for($i = 0; $i < $imx; $i++) {
//   $arr = $m_mostarr[$i]; // extract array
//   $m_msg .= $arr[0] . ' ';
//   $m_msg .= date("F d Y H:i:s.", $arr[1]) . ' ';
//   $m_msg .= " $arr[2]";
//   $m_msg .= " $arr[3]";
//   $m_msg .= "<br>\r\n";
//   }
//   $m_msg .= "</p>\r\n";
//   print "$m_msg\r\n";
//   }

   outOrderList ( $imx, $got_ord, $m_mostarr, 3, 9 );
   // outOrderList ( $imx, $got_ord, $m_mostarr, 6, $imx );

} else {
   $m_msg = "<p>No most recent ...</p>";
   print "$m_msg\r\n";
}

?>
 

<p align="center"><span style="background-color: #FFFFFF">|* <a href="index.html">index</a>
 *|</span></p>

<p>EOP</p>

</body>
</html>
<!-- 5 August 2005 - imagesa9.php Version 0.0.3 - friendofflowers.com - grm -->

index

Valid HTML 4.01 Transitional