ホームページ  >  記事  >  バックエンド開発  >  フォルダーとその下のすべてのファイルを削除およびコピーするための PHP 実装コード_PHP チュートリアル

フォルダーとその下のすべてのファイルを削除およびコピーするための PHP 実装コード_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 15:13:03762ブラウズ

コードをコピー コードは次のとおりです:

/*Copy xCopy 関数の使用法:
* xCopy("feiy","feiy2",1): feiy の下にあるファイルをコピーしますfeiy2 (サブディレクトリを含む)
* xCopy("feiy","feiy2",0): feiy 配下のファイルをサブディレクトリを除いて feiy2 にコピーします
*パラメータの説明:
* $source: コピー元のディレクトリ名
* $destination: コピー先のディレクトリ名
* $child: コピーする場合、サブディレクトリも含まれますか?
*/
function xCopy($source, $destination, $child){
if (!file_exists($destination))
{
($destination, '/ ')、0777))
' ;
}
if(!is_dir($source)){
return 0;
}
if(!is_dir($destination)){
mkdir ($destination,0777);
$handle=dir($source);
while($entry=$handle->read()){
if(($entry!=".")&&($entry!="..")) {
if(is_dir($source." /".$entry)){
if($child)
xCopy($source."/".$entry,$destination."/".$entry,$child) ;
}
else{
copy($source."/".$entry,$destination."/".$entry);
}
}
}
return 1;
}


/* deldir 関数の使用法を削除します:
* deldidr("feiy"): サブディレクトリを含む feiy を削除します
* パラメータの説明: * $dir: 削除するディレクトリの名前

*/
function deldir($dir ) {
if (!file_exists($dir)){return true;
}else{@chmod($dir, 0777);}
$dh=opendir($dir);
while ($file=readdir($dh) )) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
unlink( $fullpath);
} else {

Closedir($dh);

if(rmdir($dir)) {
return true;
} else {
return false;
}
}

?>







http://www.bkjia.com/PHPjc/326538.html

www.bkjia.com

tru​​ehttp://www.bkjia.com/PHPjc/326538.html

技術記事コピー コードは次のとおりです。 ?php /*Copy xCopy 関数の使用法: * xCopy("feiy","feiy2",1): feiy の下にあるファイルをサブディレクトリも含めて feiy2 にコピーします* xCopy("feiy","feiy2" 、0): feiy の下にファイルをコピーします...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。