note 26731 modified in function.copy by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:55:32 +0000 |
| Subject: | note 26731 modified in function.copy by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80058@lists.php.net to get a copy of this message | ||
This set of functions copies all files, directories (even they are full) may be usefull.
<?php
function my_copy($oldname, $newname)
{
if(is_file($oldname)){
$perms = fileperms($oldname);
return copy($oldname, $newname) && chmod($newname, $perms);
}
else if(is_dir($oldname)){
my_dir_copy($oldname, $newname);
}
else{
die("Cannot copy file: $oldname (it's neither a file nor a directory)");
}
}
function my_dir_copy($oldname, $newname)
{
if(!is_dir($newname)){
mkdir($newname);
}
$dir = opendir($oldname);
while($file = readdir($dir)){
if($file == "." || $file == ".."){
continue;
}
my_copy("$oldname/$file", "$newname/$file");
}
closedir($dir);
}
?>
--was--
This set of functions copies all files, directories (even they are full) may be usefull.
function my_copy($oldname, $newname)
{
if(is_file($oldname)){
$perms = fileperms($oldname);
return copy($oldname, $newname) && chmod($newname, $perms);
}
else if(is_dir($oldname)){
my_dir_copy($oldname, $newname);
}
else{
die("Cannot copy file: $oldname (it's neither a file nor a directory)");
}
}
function my_dir_copy($oldname, $newname)
{
if(!is_dir($newname)){
mkdir($newname);
}
$dir = opendir($oldname);
while($file = readdir($dir)){
if($file == "." || $file == ".."){
continue;
}
my_copy("$oldname/$file", "$newname/$file");
}
closedir($dir);
}
http://php.net/manual/en/function.copy.php