note 103732 added to function.copy
| From: | cory at veck dot ca | Date: | Sat, 30 Apr 2011 06:17:44 +0000 |
| Subject: | note 103732 added to function.copy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179298@lists.php.net to get a copy of this message | ||
My own 'cp -R' written in PHP.
Hopefully it will work for your situation. I'm using it in a web based file manager for my CMS.
<?php
define('DS', DIRECTORY_SEPARATOR); // I always use this short form in my code.
function copy_r( $path, $dest )
{
if( is_dir($path) )
{
@mkdir( $dest );
$objects = scandir($path);
if( sizeof($objects) > 0 )
{
foreach( $objects as $file )
{
if( $file == "." || $file == ".." )
continue;
// go on
if( is_dir( $path.DS.$file ) )
{
copy_r( $path.DS.$file, $dest.DS.$file );
}
else
{
copy( $path.DS.$file, $dest.DS.$file );
}
}
}
return true;
}
elseif( is_file($path) )
{
return copy($path, $dest);
}
else
{
return false;
}
}
?>
----
Server IP: 216.235.13.26
Probable Submitter: 69.11.107.156
----
Manual Page -- http://www.php.net/manual/en/function.copy.php
Edit -- https://master.php.net/note/edit/103732
Del: integrated -- https://master.php.net/note/delete/103732/integrated
Del: useless -- https://master.php.net/note/delete/103732/useless
Del: bad code -- https://master.php.net/note/delete/103732/bad+code
Del: spam -- https://master.php.net/note/delete/103732/spam
Del: non-english -- https://master.php.net/note/delete/103732/non-english
Del: in docs -- https://master.php.net/note/delete/103732/in+docs
Del: other reasons-- https://master.php.net/note/delete/103732
Reject -- https://master.php.net/note/reject/103732
Search -- https://master.php.net/manage/user-notes.php