This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.php
86 lines (73 loc) · 2.12 KB
/
copy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST['path_1']) && isset($_POST['path_2']) && isset($_POST['array'])) {
$path_1 = $_POST['path_1'];
$path_2 = $_POST['path_2'];
$array = $_POST['array'];
$val = true;
$show_duplicate = false;
$success = "success";
function full_copy( $source, $target ) {
if ( is_dir( $source ) ) {
@mkdir( $target );
$d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) ) {
if ( $entry == '.' || $entry == '..' ) {
continue;
}
$Entry = $source . '/' . $entry;
if ( is_dir( $Entry ) ) {
full_copy( $Entry, $target . '/' . $entry );
continue;
}
copy( $Entry, $target . '/' . $entry );
}
$d->close();
}else {
copy( $source, $target );
}
}
foreach ($array as $value) {
try{
if(file_exists($path_2."/".$value)){
// Rename and the Paste Files
if(is_dir($path_1."/".$value)){
$n = $path_1."/".$value."/".$value;
$p = $path_2."/".$value;;
if($n == $p){
$success = "error";
}else{
full_copy($path_1."/".$value , $path_2."/"."(Copy) ".$value);
}
}else{
copy($path_1."/".$value, $path_2."/"."(Copy) ".$value);
}
$show_duplicate = true;
}else{
// Simple Paste
if(is_dir($path_1."/".$value)){
$n = $path_1."/".$value."/".$value;
$p = $path_2."/".$value;
if($n == $p){
$success = "error";
}else{
full_copy($path_1."/".$value , $path_2."/".$value);
}
}else{
copy($path_1."/".$value, $path_2."/".$value);
}
$show_duplicate = false;
}
} catch (EngineException $e) {
echo 'Message: ' .$e->getMessage();
$val = false;
}
}
if($show_duplicate == true){
echo $success;
}else{
echo $success;
}
}
}
?>