コード例 #1
0
ファイル: p4CopyScript.php プロジェクト: brianjchow/CS105
function rCopy($src, $dst)
{
    $dir = opendir($src);
    @mkdir($dst, 0777);
    while (($file = readdir($dir)) !== false) {
        if ($file != '.' && $file != '..') {
            if (is_dir($src . "/" . $file)) {
                rCopy($src . "/" . $file, $dst . "/" . $file);
            } else {
                copy($src . "/" . $file, $dst . "/" . $file);
            }
        }
    }
    closedir($dir);
}
コード例 #2
0
ファイル: ofc.php プロジェクト: arribanz/live
function rCopy($old_path, $new_path)
{
    //*************************************
    //Recursively copy $old_path to $new_path
    global $_, $WHSPC_SLASH, $EX, $message;
    //Avoid a bottomless pit of sub-directories:
    //    ok: copy root/1/ to root/1/Copy_of_1/
    //NOT OK: copy root/1/ to root/1/2/Coyp_of_1/
    //
    //First, trim / and white-space that will mess up strlen() check.
    $old_path = trim($old_path, $WHSPC_SLASH);
    $new_path = trim($new_path, $WHSPC_SLASH);
    //
    $test_path = dirname($new_path);
    while (strlen($test_path) >= strlen($old_path)) {
        $test_path = dirname($test_path);
        if ($test_path == $old_path) {
            $message .= $EX . ' <b>' . $_['rCopy_msg_01'] . '</b><br>';
            return false;
        }
    }
    if (is_file($old_path)) {
        return copy($old_path, $new_path);
    }
    if (is_dir($old_path)) {
        $dir_list = scandir($old_path);
        //MUST come before mkdir().
        mkdir($new_path, 0755);
        if (sizeof($dir_list) > 0) {
            foreach ($dir_list as $file) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                rCopy($old_path . '/' . $file, $new_path . '/' . $file);
            }
        }
        return true;
    }
    return false;
    //$old_path doesn't exist, or, I don't know what it is.
}
コード例 #3
0
function rCopy($old_path, $new_path)
{
    //**************************************
    global $_, $WHSPC_SLASH, $EX, $message;
    //Recursively copy $old_path to $new_path
    //Both $old_ & $new_path must ALREADY be in OS/file system's encoding.
    //(ie: usually UTF-8, but often ISO-8859-1 for Windows.)
    //Return number of successful copy's + mkdir's, or 0 on error.
    //$old_path & $new_path must already be in OS/filesystem's file name encoding
    //Avoid a bottomless pit of sub-directories:
    //    ok: copy root/1/ to root/1/Copy_of_1/
    //NOT OK: copy root/1/ to root/1/2/Copy_of_1/
    //
    $error_code = 0;
    //First, trim / and white-space that will mess up strlen() check.
    $old_path = trim($old_path, $WHSPC_SLASH);
    $new_path = trim($new_path, $WHSPC_SLASH);
    //
    $test_path = dirname($new_path);
    while (mb_strlen($test_path) >= mb_strlen($old_path)) {
        $test_path = dirname($test_path);
        if ($test_path == $old_path) {
            $message .= $EX . ' <b>' . hsc($_['rCopy_msg_01']) . '</b><br>';
            return 0;
        }
    }
    if (is_file($old_path)) {
        return copy($old_path, $new_path) * 1;
    }
    if (is_dir($old_path)) {
        $dir_list = scandir($old_path);
        //MUST come before mkdir().
        $error_code = mkdir($new_path, 0755) * 1;
        if (sizeof($dir_list) > 0) {
            foreach ($dir_list as $file) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                $error_code += rCopy($old_path . '/' . $file, $new_path . '/' . $file);
            }
        }
        return $error_code;
    }
    return 0;
    //$old_path doesn't exist, or, I don't know what it is.
}