" comment * * * Author: David Altherr; www.davidaltherr.net */ ?>
| Start at file system path: | |
| Return files of extension: | |
";
/* return shortened syntax of file size */
function format_file_size($foo){
if ($foo >= 1073741824) {
$foo = round($foo / 1073741824 * 100) / 100 . "g";
} elseif ($foo >= 1048576) {
$foo = round($foo / 1048576 * 100) / 100 . "m";
} elseif ($foo >= 1024) {
$foo = round($foo / 1024 * 100) / 100 . "k";
} else {
$foo = $foo . "b";
}
return $foo;
}
/* parse current microtime string into numeric */
function getmicrotime(){
$fn_mtime = microtime();
$fn_mtime = explode(" ",$fn_mtime);
$fn_mtime = $fn_mtime[1] + $fn_mtime[0];
return ($fn_mtime);
}
/* validate file extension */
function is_file_type($ft,$foo){
global $cur_fs_path;
$ft_len = strlen($ft);
$foo_len = strlen($foo);
$is = 1;
/* file and dir name excludes */
if(0){
return 0;
}
/* test for dir or valid file extension */
if(is_dir($cur_fs_path.$foo) || !$ft_len || $ft=='*'){
$is = 1;
} else {
$is = stristr(substr($foo,$foo_len-$ft_len,$ft_len),$ft);
}
return $is;
}
/* parses a file system directory */
function get_dir_array($s_path){
global $file_type
,$root_fs_path
,$cur_fs_path
,$db_connect
,$total_file_count
,$total_file_size;
/* load directory Into array */
$handle=opendir($s_path);
while ($file = readdir($handle)) {
if ( ($file != ".") && ($file != "..") && (is_file_type($file_type,$file)) ) {
$dir_item_array[count($dir_item_array)] = $file;
}
}
if(count($dir_item_array)){
//Clean up and sort
closedir($handle);
sort($dir_item_array);
$file_count = 1;
//return $dir_item_array;
while (list($key, $val) = each($dir_item_array)) {
/* if fs object is a directory, recurse */
if (is_dir($s_path.$val)) {
$prev_fs_path=$cur_fs_path;
$cur_fs_path.=$val."\\";
echo '
| '.$cur_fs_path.' '; get_dir_array($cur_fs_path); echo ' |
'.htmlspecialchars($file_contents).''; /* modify html tags */ /* regexp strings ---> */ /* define the regexp replacement strings */ $file_contents = preg_replace("/(]*>)/i","",$file_contents); $file_contents = preg_replace("/(<[\/]font[^>]*>)/i","",$file_contents); /* uncomment this line to see the edited file contents */ //echo '
'.htmlspecialchars($file_contents).''; /* write edited contents to file */ $fd = fopen ("$cur_fs_path$file_name", "r+"); fwrite($fd,$file_contents); fclose ($fd); } } }else{ echo " No '.$file_type' files in directory tree."; } } /* returns only files of following extension */ if(!isset($file_type)){ $file_type = 'html'; } /* edit directory */ //$root_fs_path = "c:\\your_file_path\\"; $cur_fs_path = $root_fs_path; /* intialize counter */ $total_file_count = 0; /* start recursive directory grab */ $run_time_start = getmicrotime(); if(strlen($cur_fs_path)>0){ echo "Directory List:
| '.$cur_fs_path.' '; get_dir_array($root_fs_path); echo ' |