note 42365 added to function.copy
| From: | raven_25041980 at yahoo dot com | Date: | Thu, 13 May 2004 15:13:55 +0000 |
| Subject: | note 42365 added to function.copy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69572@lists.php.net to get a copy of this message | ||
To objobj at hotmail dot com:
You forgot to chmod the files also... So, here's the improvement to the improvement... :D Hope
it's useful further on...
<?php
// it copies $wf to $wto
function copy_dirs($wf, $wto)
{
if (!file_exists($wto))
{
mkdir($wto, 0777);
}
$arr=ls_a($wf);
foreach ($arr as $fn)
{
if($fn)
{
$fl=$wf."/".$fn;
$flto=$wto."/".$fn;
if(is_dir($fl)) copy_dirs($fl, $flto);
else // begin 2nd improvement
{
@copy($fl, $flto);
chmod($flto, 0666);
} // end 2nd improvement
}
}
}
// This function lists a directory
function ls_a($wh)
{
if ($handle = opendir($wh))
{
while (false !== ($file = readdir($handle)))
{
if ($file !== "." && $file !== ".." )
{
if(!$files) $files=$file;
else $files = $file."\r\n".$files;
}
}
closedir($handle);
}
$arr=explode("\r\n", $files);
for($i=0; $i<count($arr); $i++)
{
echo "<br />".$arr[$i];
}
return $arr;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.copy.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42365
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42365&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42365&report=yes
Search -- http://master.php.net/manage/user-notes.php