test8.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:17 2007 from test8.php 2005/11/22 3.8 KB bytes.


<html>
<head>
<title>test8.php</title>

</head>

<body>

<p>File List </p>


<?php 
$m_mostarr = Array();
$m_fil_list = Array();

$m_mostrec = 0;
$m_mostnam = '';
$m_mostcnt = 0;
// Examples for higlight function below
// $phrase = "This is a test";
// $search = "T";
// $test = highlight($phrase);
// $test1 = highlight($phrase,$search);
// $test2 = highlight($phrase,$search,"green");
// $test3 = highlight($phrase,$search,"#000000","rgb(255,255,255)");
function highlight()
{
   $numargs = func_num_args(); // get argument COUNT
   if ($numargs < 1) {
   echo "Error in function highlight(): No arguments passed to function";
   }
   $string = func_get_arg(0); // get the phrase to highligh
   if($numargs >= 2) {
   $keyword = func_get_arg(1); // search within phrase for
   }else{
   $keyword = $string; // else the whole phrase
   }
   if($keyword == "") { // note 2nd arg blank
   $keyword = $string; // also means 'whole' string
   }
   if($numargs >= 3) { // if given a 'color' for background
   $b = func_get_arg(2); // get color
   }else{
   $b = "yellow"; // else default to yellow
   }
   if($numargs >= 4) { // if given a 'color' foreground
   $f = func_get_arg(3); // get given
   }else{
   $f = "black"; // else use BLACK
   }
   $string = preg_replace('/('.$keyword.')/i', "<span style=\"color: $f; background-color: $b;\">$1</span>", $string);
   return $string;
}


function isImageFile ( $file ) {
   $fil = $file;
   $pos = strrpos( $file, '/' );
   print "checking $file ";
   if ($pos > 0) {
   $fil = substr($file, $pos);
   }
   print "$fil ";
   $pos2 = strrpos ( $fil, '.' );
   if ($pos2 > 0) {
   $suff = strtolower(substr($fil, ($pos2 + 1)));
   print "$suff ";
   if ( ($suff == 'jpg') ||
   ($suff == 'gif') ||
   ($suff == 'png') ){
   print " ". highlight("ok") . "<br>\r\n";
   return 1;
   }
   }
   print " failed<br>\r\n";
   return 0;
}

function scanFolders ( $folder, $depth ) {
   global $m_fil_list;
 $d = dir($folder); // start with local
 $count = 0;
 // build up a LIST of directories, and files, in this folder
 while($entry = $d->read()) {
 if ($entry != "." && $entry != "..") {
   $locpath = substr($folder,0,(strlen($folder)-1)).$entry;
 if (is_dir($locpath)) {
 $dlist[] = $locpath . '/.';
   } else {
   $count++;
 $m_fil_list[] = $locpath;
   // print "added $locpath<br>\r\n";
 } 
 } 
 } 
 $d->close();
 if (isset($dlist)) {
 asort($dlist);
 foreach ($dlist as $fil) {
   $count += scanFolders ( $fil, ($depth + 1) );
   }
 }
 return $count;
}


function getImageList () { 
   global $m_mostarr, $m_fil_list;
   global $m_mostrec, $m_mostnam, $m_mostcnt;
   $mdir = '.';
   $cnt = scanFolders ( $mdir, 0 );
   print "Found " . highlight($cnt) . " files to process ...<br>\r\n";
   if (isset($m_fil_list)) {
   // asort($m_fil_list);
   foreach ($m_fil_list as $fil) {
   $locpath = $fil; // note: is full path/name
   $size = filesize($locpath);
   $filtm = filemtime($locpath);
   if( isImageFile( $fil ) ) {
   $arr = array();
   $arr[] = $fil; // 'temp' + class + number[1-9999] + '.jpg'
   $arr[] = $filtm; // keep the file time
   $arr[] = $size; // keep file size
   $arr[] = 0; // sort order ... done later ... on $filtm value
   $arr[] = $locpath; // keep WHOLE (relative) name
   // ==================================================
   $m_mostarr[] = $arr; // keep the files that MATCH class
   $m_mostcnt++; // bump COUNT
   if( $filtm > $m_mostrec ) {
   $m_mostrec = $filtm;
   $m_mostnam = $fil;
   }
   }
   }
 }
} // end func getImageList ()

getImageList();
$m_msg = '';
if ($m_mostcnt > 0) {
   $m_msg = "Got count of " . highlight($m_mostcnt) . " ...";
} else {
   $m_msg = "Got count NO COUNT!";
}
print "$m_msg\r\n";

?>
 


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

</body>
</html>

index

Valid HTML 4.01 Transitional