test3.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:16 2007 from test3.php 2005/08/12 5.9 KB bytes.

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

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

<p>Full Directory List</p>
<?php 

$g_total = 0;


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 < 1000) {
 $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 getUsed ($dirName) {
   global $g_total;
   $totused = 0;
   $d = dir($dirName);
   while (false !== ($entry = $d->read())) {
   $locpath = $dirName.'/'.$entry;
 $size = filesize($locpath);
   $g_total += $size;
   $totused += getBlkSz($size);
 if ($entry != "." && $entry != "..") { 
   if (is_dir($locpath)) {
   $totused += getUsed ($locpath);
   }
   }
   }
   return $totused;
}

$used = getUsed('.');
print "<p>Total Used: $used (" . getSizeStr($used) . ") bytes ... ($g_total)";

?>
   
<?php 

function getDirList ($dirName, $dep) { 
 $d = dir($dirName); 
 $head = "-";
 for($i = 0; $i < $dep; $i++) {
 $head = $head."-";
 }
 while($entry = $d->read()) { 
 $locpath = $dirName."/".$entry;
 if ($entry != "." && $entry != "..") { 
 if (is_dir($locpath)) { 
 getDirList($locpath, ($dep + 1)); 
 } else { 
 echo $head." ".$locpath."<br>\n"; 
 } 
 } 
 } 
 $d->close(); 
} 

 // getDirList(".",0); 

?>

<p>Another File List, in date order</p>

<?php 

$dirpath = getcwd() . "/";
$dir = opendir($dirpath);
$files = array();
while ($file = readdir($dir)) {
 $localpath = $dirpath.$file;
 
 if (is_file($localpath)) {
 $key = filemtime($localpath).md5($file);
 $files[$key] = $file;
 }
}
ksort($files);
foreach ($files as $file) {
 // echo "$file<br>";
} 

$eol = "\n";
$m_msg = '<p align="center">'.$eol;
$m_msg .= '<a href="';
$m_msg .= $this->SELF;
$m_msg .= '?dir=images">';
$m_msg .= 'images</a></p>'.$eol;
print $m_msg;

?>

<p>And a callback method</p>

<p align="center">
<a href="<? echo $this->SELF; ?>?dir=net2ftp">net2ftp</a> or 
<a href="<?php echo $this->SELF; ?>?dir=.">Clear</a>
</p>

<?php

$directory = $_REQUEST["dir"]; // lets fetch the variable: REQUEST works for both, POST and GET methods
echo "Got dir=".$directory."<br>";
if (substr($directory, 0, 1) == "/")
 $directory = "";
$directory = str_replace ("./", "", $directory);
$directory = str_replace (".", "", $directory);

echo "After=".$directory."<br>";

if ($directory != @$null) { // lets check if the variable "dir" has something in it, otherwise lets just print out the empty document
 if ($dir = @opendir($directory)) { // changed "./" to the directory variable
 echo ("Listing contents of <b>$directory</b><br><br>\n"); // i just added this thing
 while (($file = readdir($dir)) !== false) {
 if ($file != "." && $file != "..") {
 $location = "$directory/$file";
 $type = filetype($location);
 $size = filesize($location);
 if (is_dir($location) == true) {
 echo ("$type - <a href=\"dir.php?dir=$location\">$file</a><br>\n");
 }
 else {
 echo ("$type - <a href=\"$location\">$file</a> - $size Bytes<br>\n");
 }
 }
 }
 closedir($dir);
 }
}

function isImageFile ( $file ) {
   $pos = strrpos( $file, '/' );
   if ($pos > 0) {
   $fil = substr($file, $pos);
   $pos2 = strrpos ( $fil, '.' );
   if ($pos2 > 0) {
   $suff = strtolower(substr($fil, ($pos2 + 1)));
   if ($suff == 'jpg') {
   return 1;
   }
   }
   }
   return 0;
}

function scanFolders ( $folder, $fillist, $depth ) {
 $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++;
 $fillist[] = $locpath;
 } 
 } 
 } 
 $d->close();
 if (isset($dlist)) {
 asort($dlist);
 foreach ($dlist as $fil) {
   $count += scanFolders ( $fil, $fillist, ($depth + 1) );
   }
 }
 return $count;
}


function getImageList () { 
   global $m_mostarr;
   global $m_mostrec, $m_mostnam, $m_mostcnt;
   $fillist = Array();
   $cnt = scanFolders ( ".", &fillist, 0 );
   if (isset($fillist)) {
   asort($fillist);
   foreach ($fillist 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 ()

?>
 


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

</body>
</html>
 

index

Valid HTML 4.01 Transitional