-
-
// FileName: rewrite.php
- // 功能: 重写xxx目录下所有的htm文件(也可以是php文件)
- // Author: windlike.cublog.cn
function getFileInfo($dir, $type){
- global $arr_file;
- $mydir = dir($dir);
- while(false !== ($file = $mydir->read())){
- if((is_dir("$dir/$file")) && ($file != ".") && ($file != "..")){
- getFileInfo("$dir/$file",$type);
- }else{
- if(($file != ".") && ($file != "..")){
- $path_info = pathinfo("$file");
- if($path_info["extension"] == $type){
- $arr_file["$dir"][] = $file;
- }
- }
- }
- }
- $mydir->close();
- }
function Rewrite_File($content){
- global $arr_file;
- foreach($arr_file as $key=>$arr){
- foreach($arr as $value){
- $file = $key . '/' . $value;
- $fp = fopen($file, 'w');
- fwrite($fp, $content);
- fclose($fp);
- }
- }
- }
//
- $dir = "xxx";
- $type = "htm";
- $content = "hello world!\n";
- getFileInfo($dir, $type);
- Rewrite_File($content);
- ?>
-
复制代码
以上文件在我的电脑上已经通过测试。为了使用起来更方便,我试着写了一个Rewrite类,可是运行时总是提示错误: Fatal error: Call to undefined function: getfileinfo() in d:\usr\www\html\test_class.php on line 24
刚接触php类,路过的朋友帮我看一下是哪里的错误。
-
-
// FileName: test_class.php
- class Rewrite_File{
- var $file_dir;
- var $file_content;
- var $file_type;
- var $arr_file_info;
-
- function Rewrite_File($file_dir, $file_content, $file_type){
- $this->file_dir = $file_dir;
- $this->tem_file_dir = $file_dir;
- $this->file_content = $file_content;
- $this->file_type = $file_type;
- }
-
- function getFileInfo(){
- $dir = $this->tem_file_dir;
- $mydir = dir($dir);
- while(false !== ($file = $mydir->read())){
- if((is_dir("$dir/$file")) && ($file != ".") && ($file != "..")){
- //
$this->tem_file_dir = $dir;
- getFileInfo();
- }else{
- if(($file != ".") && ($file != "..")){
- $path_info = pathinfo("$file");
- if($path_info["extension"] == $this->file_type){
- $this->arr_file_info["$dir"][] = $file;
- }
- }
- }
- }
- $mydir->close();
- }
-
- function rewriteFile(){
- foreach($this->arr_file_info as $key=>$arr){
- foreach($arr as $value){
- $file = $key . '/' . $value;
- $fp = fopen($file, 'w');
- fwrite($fp, $this->content);
- fclose($fp);
- }
- }
- }
}
$option = new Rewrite_File("xxx","hello \nworld","htm");
- $option->getFileInfo();
- echo "
- print_r($option->arr_file_info);
- echo "";
- $option->rewriteFile();
?>
-
复制代码
|