" 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 '
'; $cur_fs_path = $prev_fs_path; /* if fs object is a file, operate */ } else { /* grab file name */ $file_name = $val; /* determine file size */ $file_size = filesize("$cur_fs_path$file_name"); $total_file_size += $file_size; $file_size_disp = format_file_size($file_size); /* echo file name and size*/ echo "   ".($file_count++).".$file_name $file_size_disp "; $total_file_count++; /* read file */ $fd = fopen ("$cur_fs_path$file_name", "r+"); $file_contents = ''; $foo = (double) 0; while (!feof ($fd)) { $file_contents .= fgets($fd, 1024); $foo++; /* check for infinite recursion and very large files */ if($foo > (double) 1000000){ echo "file read error or file larger than 1GB."; die; } } fclose ($fd); /* delete current file contents */ $fd = fopen ("$cur_fs_path$file_name", "w+"); fwrite($fd,''); fclose ($fd); /* uncomment this lines to see the existing file contents: useful for testing */ //echo '

previous:

'.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 '

current:
'.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:

"; echo '
'.$cur_fs_path.'
'; get_dir_array($root_fs_path); echo '
'; } $run_time_stop = getmicrotime(); $total_run_time = $run_time_stop - $run_time_start; echo "
Total files loaded: $total_file_count files"; if($total_file_size>0 && $total_run_time>0){ echo "
Total size of data: ".format_file_size($total_file_size).""; echo "
Average file size: ".format_file_size($total_file_size/$total_file_count).""; echo "
Total script time: ".round($total_run_time,3)." seconds"; } ?>