note 26192 modified in function.copy by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:55:34 +0000 |
| Subject: | note 26192 modified in function.copy by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80003@lists.php.net to get a copy of this message | ||
yet another mod to the rec_copy function... I found that the other mods left the directory being
copied TO open to the public for writeing (0777) instead of 0775 for only PHP writeing... they also
altered the current working dir, and never changed back :)
<?php
function dir_copy ($from_path, $to_path)
{
$this_path = getcwd();
if(!is_dir($to_path))
{ mkdir($to_path, 0775);
}
if (is_dir($from_path))
{
chdir($from_path);
$handle=opendir('.');
while (($file = readdir($handle))!==false)
{
if (($file != ".") && ($file != ".."))
{
if (is_dir($file))
{
chdir($this_path);
rec_copy ($from_path.$file."/", $to_path.$file."/");
chdir($this_path);
chdir($from_path);
}
if (is_file($file))
{
chdir($this_path);
copy($from_path.$file, $to_path.$file);
chdir($from_path);
}
}
}
closedir($handle);
}
chdir($this_path);
}
?>
--was--
yet another mod to the rec_copy function... I found that the other mods left the directory being
copied TO open to the public for writeing (0777) instead of 0775 for only PHP writeing... they also
altered the current working dir, and never changed back :)
function dir_copy ($from_path, $to_path)
{
$this_path = getcwd();
if(!is_dir($to_path))
{ mkdir($to_path, 0775);
}
if (is_dir($from_path))
{
chdir($from_path);
$handle=opendir('.');
while (($file = readdir($handle))!==false)
{
if (($file != ".") && ($file != ".."))
{
if (is_dir($file))
{
chdir($this_path);
rec_copy ($from_path.$file."/", $to_path.$file."/");
chdir($this_path);
chdir($from_path);
}
if (is_file($file))
{
chdir($this_path);
copy($from_path.$file, $to_path.$file);
chdir($from_path);
}
}
}
closedir($handle);
}
chdir($this_path);
}
http://php.net/manual/en/function.copy.php