將文件夾下的各文件內容寫入一個文件中

<?phpphp

  function show($dir,$input){spa

      $opendir = opendir($dir) or die("文件打開失敗");
       while ($read = readdir($opendir)) {
            if(!isset($cont)){
                $cont=null;
            }
            if($read !="." && $read !=".."){
              $path = $dir."/".$read;
              if(is_dir($path)){
                  show($path,$input);
              }else{
                  // file_put_contents($input,file_get_contents($path),FILE_APPEND);
                  $cont .= file_get_contents($path);
              }
            }
          }
          file_put_contents($input,$cont,FILE_APPEND);
     }
get

     $dir="H:\wamp\www\demo5.1";
     $input="input.txt";
     show($dir,$input);
input

 ?>
 io

相關文章
相關標籤/搜索