這篇文章主要介紹了php通過遞歸方式復制目錄和子目錄的方法,涉及php遞歸及目錄操作的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php通過遞歸方式復制目錄和子目錄的方法。分享給大家供大家參考。具體實現方法如下:
- <?php
- function recurse_copy($src,$dst){
- $dir = opendir($src);
- @mkdir($dst);
- while(false !== ( $file = readdir($dir)) ) {
- if (( $file != '.' ) && ( $file != '..' )) {
- if ( is_dir($src . '/' . $file) ) {
- recurse_copy($src.'/'.$file,$dst.'/'.$file);
- }
- else {
- copy($src.'/'.$file,$dst.'/'.$file);
- }
- }
- }
- closedir($dir);
- }
- ?>
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答