test6.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:17 2007 from test6.php 2005/08/09 16.6 KB bytes.

<html>
<head>
<title>test6.php</title>
</head>
<body background="cldsg.jpg">

<h1 align="center">test6.php</h1>

<p>Single Directory Listing</p>

<?php 

$m_folder = 'c:/HOMEPAGE/russ4/images/.';
$m_mostcnt = 0;
$m_mostnam = ' ';
$m_mostrec = 0;
$m_mostarr = array();
$m_msg = ' ';

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 mostRecentModifiedFileTime($dirName,$doRecursive) {
 $d = dir($dirName);
 $lastModified = 0;
 while($entry = $d->read()) {
 if ($entry != "." && $entry != "..") {
 if (!is_dir($dirName."/".$entry)) {
 $currentModified = filemtime($dirName."/".$entry);
 } else if ($doRecursive && is_dir($dirName."/".$entry)) {
 $currentModified = mostRecentModifiedFileTime($dirName."/".$entry,true);
 }
 if ($currentModified > $lastModified){
 $lastModified = $currentModified;
 }
 }
 }
 $d->close();
 return $lastModified;
} 

function filemtime_remote($uri)
{
 $uri = parse_url($uri);
 $handle = @fsockopen($uri['host'],80);
 if(!$handle)
 return 0;

 fputs($handle,"GET $uri[path] HTTP/1.1\r\nHost: $uri[host]\r\n\r\n");
 $result = 0;
 while(!feof($handle))
 {
 $line = fgets($handle,1024);
 if(!trim($line))
 break;

 $col = strpos($line,':');
 if($col !== false)
 {
 $header = trim(substr($line,0,$col));
 $value = trim(substr($line,$col+1));
 if(strtolower($header) == 'last-modified')
 {
 $result = strtotime($value);
 break;
 }
 }
 }
 fclose($handle);
 return $result;
}
// echo filemtime_remote('http://www.somesite.com/someimage.jpg');

function isMyFile( $file, $cls )
{
   $ln = strlen($file);
   if($ln >= (4+1+4+1+3)) {
   if( ( substr($file,-4,4) == '.jpg' ) &&
   ( substr($file,0,4) == 'temp' ) ) {
   if( $cls == substr($file,4,1) ) { // get 'a', 'b', 'c'
   // got our TYPE
   return 1;
   } // got class, day, set
   } // got 'temp' part
   } // get length
   return 0;
}

function getDirList ($dirName, $dep) { 
 $fdrgif = 'folder.gif';
 $filgif = 'file.gif';
 $d = dir($dirName); 
 while($entry = $d->read()) { 
 $locpath = $dirName."/".$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; 

 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;
 $stats = stat($locpath);
 $size = $stats['size'];
 // $totb += $size;
 $totb += getBlkSz($size);
 $filst = lstat($locpath);
 $perm = TranslatePerm($filst['mode']);
 echo "<tr><td><img src=\"" . $fdrgif . "\"></td><td>".$dir."</td><td>$size</td><td><b>DIR</b></td><td>$perm</td></tr>\n";
 }
 }

 if (isset($fillist)) {
 asort($fillist);
 foreach ($fillist as $fil) {
 $locpath = $dirName."/".$fil;
 $size = filesize($locpath);
 // $totb += $size;
 $totb += getBlkSz($size);
   $filtm = filemtime($locpath);
   if( $filtm > $mostrec ) {
   $mostrec = $filtm;
   $mostnam = $locpath;
   }
 $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']);
 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";
 }
 }
 
 // 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";

} 

function getDirList2 ($dirName, $dep, $mostrec, $mostnam, $mostcnt, $mostarr, $add_tab ) { 
 $fdrgif = 'folder.gif';
 $filgif = 'file.gif';
 $d = dir($dirName); 
 while($entry = $d->read()) { 
 $locpath = $dirName."/".$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;
 $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;
 $size = filesize($locpath);
 // $totb += $size;
 $totb += getBlkSz($size);
   $filtm = filemtime($locpath);
   if( isMyFile( $fil, 's' ) ) {
   if( $filtm > $mostrec ) {
   $mostrec = $filtm;
   $mostnam = $locpath;
   }
   $arr = array();
   //$arr[] = $locpath;
   $arr[] = $fil; // 'temp' + class + '.jpg'
   $arr[] = $filtm; // keep the file time
   $arr[] = $size; // keep file size
   $arr[] = 0; // sort order
   $arr[] = $locpath; // keep WHOLE (relative) name
   //$mostarr[] = $locpath; // keep the files that MATCH class
   $mostarr[] = $arr; // keep the files that MATCH class
   $mostcnt++;
   }
 $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";
 }
} 

// getDirList(".",0); 
// getDirList2 (".", 0, &$m_mostrec, &$m_mostnam);
// getDirList2 ("c:/HOMEPAGE/russ4/images/.", 0, &$m_mostrec, &$m_mostnam, 
//getDirList2 ($m_folder, 0, &$m_mostrec, &$m_mostnam, &$m_mostcnt,
// &$m_mostarr, 0);

if( $m_mostrec > 0 ) {
   $imx = count( $m_mostarr );
   $imx2 = $imx; // copy count
   $got_ord = 1;
   while($imx2) {
   $ft = 0;
   $idx = $imx;
   for($i = 0; $i < $imx; $i++) {
   $arr = $m_mostarr[$i]; // extract array
   if( $arr[3] == 0 ) {
   if( $arr[1] > $ft ) {
   $ft = $arr[1];
   $idx = $i;
   }
   }
   }
   if( $idx < $imx ) {
   // found highest, latest
   $arr = $m_mostarr[$idx]; // extract array
   $arr[3] = $imx2; // set ORDER
   $m_mostarr[$idx] = $arr; // replace array
   // print "<p>Set order $arr[3]!</p>\r\n";
   } else {
   print "<p>No order!</p>\r\n";
   $got_ord = 0;
   }
   $imx2--;
   }
   $m_msg = "<p>Most recent: $m_mostnam ";
   $m_msg .= date("F d Y H:i:s.", $m_mostrec);
   $m_msg .= " ($m_mostrec) of $m_mostcnt ($imx) ...</p>";
   print "$m_msg\r\n";
   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";
   }

   $imx2 = $imx; // copy count
   if( $got_ord ) {
   $mx_ord = 9;
   $got_ord = 0;
 //print "<table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n";
   //print "<tr><td>\n";
   //print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n";
   print "<div align=\"center\">\r\n";
   print "<center>\r\n";
   print "<table border=\"2\" cellpadding=\"0\" cellspacing=\"0\" width=\"480\">\r\n";
   // print "<table>";
   while($imx2) {
   for($i = 0; $i < $imx; $i++) {
   $arr = $m_mostarr[$i]; // extract array
   if( $arr[3] == $imx2 ) {
   $m_msg = '';
   if(($got_ord % 3) == 0) {
   $m_msg .= "<tr>";
   }
   //$m_msg .= '<td>';
   $m_msg .= '<td width="160">';
   $m_msg .= "<img src=\"$arr[4]\" alt=\"";
   $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 .= "\"";
   $m_msg .= " width=\"160\" height=\"120\"";
   $m_msg .= ">";
   $m_msg .= "</td>";
   $got_ord++;
   if(($got_ord % 3) == 0) {
   $m_msg .= "</tr>";
   }
   print "$m_msg\r\n";
   break;
   }
   }
   $imx2--;
   if($got_ord >= $mx_ord) {
   break;
   }
   }
   //print "</table>";
   print "</table>\n";
   //print "</td></tr>\n";
   //print "</table>\n";
   print "</center>\r\n";
   print "</div>\r\n";
   }

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

//$rft = //filemtime_remote('http://www.friendofflowers.com/images/tempa0001.jpg');
//$date = date ("F d Y H:i:s.", $rft);
//print "<p>Remote file time for tempa0001.jpg is $rft $date</p>\r\n";
//$rft = //filemtime_remote('http://www.friendofflowers.com/images/tempa0009.jpg');
//$date = date ("F d Y H:i:s.", $rft);
//print "<p>Remote file time for tempa0009.jpg is $rft $date</p>\r\n";

?>
 

<?php 

if (isset($_REQUEST)) {
   if (isset($_REQUEST['show'])) {
   $m_show = $_REQUEST['show']; // lets fetch the variable: REQUEST works for both, POST and GET methods
   } else {
   $m_show = 'none';
   }
} else {
   $m_show = 'no request';
}
$m_page = $_GET['page'];
$m_msg = 'Value of show = ';
if (isset($m_show)) {
   $m_msg .= $m_show;
} else {
   $m_msg .= 'not set';
}
$m_msg .= 'Value of page = ';
if (isset($m_page)) {
   $m_msg .= $m_page;
} else {
   $m_msg .= 'not set';
}

print "$m_msg\r\n";

if (isset($_SERVER)) {
   print "<center><h1><a href='login.php?refurl=";
 print urlencode($_SERVER['REQUEST_URI']);
 print "'>login 1</a></h1></center>";

   print "<p>PHP_SELF: *". $_SERVER['PHP_SELF'] . "*\n";
   print "<center><h1><a href='login.php?refurl=";
 print urlencode($_SERVER['PHP_SELF']);
 print "'>login 2</a></h1></center>";

} else {
   print "<center><h1>no $_SERVER! ...";
}

?>


<?php 
/* The Purpose of this function is to display the actual time in your time zone if your web host has a different time from you. In the function, the variable $timediff is the time difference in seconds between your actual location and the location of your server or webhost. If you are ahead of your server type in a positive integer such as 7200. If you behind your server please enter a negative integer such as -7200. In the first example you are 2 hours ahead of your server. In the second example your are 2 hours behind your server. Our Goal is to return a time like Saturday, August 15, 2004 08:55:05 PM EST.
*/ 
   
function actualtime () {
   $timediff = 0 ; // The time difference, in seconds, between your server and your time, if ANY. 
   $timestamp = date('U'); // The timestamp at your server. 
   $timestamp = $timestamp + $timediff; // The calculated timestamp at your actual location. 
   $weekday = date('l', $timestamp); // Day of the week like Saturday. 
   $month = date('F', $timestamp); // Month of the year Like August. 
   $day = date('d', $timestamp); // Day of the month like 14 
   $year = date('Y', $timestamp); // A full numeric representation of a year, 4 digits like 2004 
   $hour = date('h', $timestamp); // The time in hours. 
   $minute = date('i', $timestamp); // The time in minutes. 
   $seconds = date('s', $timestamp); // The time in seconds. 
   $am_pm = date('A', $timestamp); // The Uppercase Ante meridiem and Post meridiem AM or PM. 
   $suffix = 'Eastern Time' ; // The suffix that you would like to attach at the end of your date and time.
   $actualtimeis = "{$weekday}, {$month} {$day}, {$year} {$hour}:{$minute}:{$seconds} {$am_pm} {$suffix}" ;
   return $actualtimeis ; // function ends here. 
}

echo actualtime (); // Prints something like Saturday, August 14, 2004 12:59:47 PM Eastern Time.
$url = $_SERVER['REQUEST_URI']; 
print "url = $url\r\n";

// require_once("cal01/activecalendar.php");
// $cal = new activeCalendar();
// echo $cal->showMonth();

?>
 

<p>
End of test6.php
</p>

</body>
</html>
 

index

Valid HTML 4.01 Transitional