Пример #1
0
 /**
  * Recursive copy function
  * @param str src source path
  * @param str dst source path
  * @return bool
  */
 public static function cp_r($src, $dst)
 {
     if (is_link($src)) {
         $l = readlink($src);
         if (!symlink($l, $dst)) {
             return false;
         }
     } elseif (is_dir($src)) {
         $objects = scandir($src);
         if ($objects === false) {
             return false;
         }
         foreach ($objects as $file) {
             if ($file == "." || $file == "..") {
                 continue;
             }
             if (!cp_r($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file)) {
                 return false;
             }
         }
     } else {
         if (!copy($src, $dst)) {
             return false;
         }
     }
     return false;
 }
function cp_r($from, $to)
{
    //echo "<p>cp_r($from,$to)<br>";
    if (is_file($from)) {
        //echo "copy($from,$to)<br>";
        if (is_dir($to)) {
            $to .= '/' . basename($from);
        }
        return copy($from, $to);
    }
    if (is_dir($from)) {
        $to .= '/' . basename($from);
        if (!is_dir($to) && !mkdir($to)) {
            echo "Can't mkdir({$to}) !!!";
            return False;
        }
        if (!($dir = opendir($from))) {
            echo "Can't open {$from} !!!";
            return False;
        }
        while ($file = readdir($dir)) {
            if ($file != '.' && $file != '..') {
                if (!cp_r($from . '/' . $file, $to)) {
                    return False;
                }
            }
        }
    }
    return True;
}