-
Notifications
You must be signed in to change notification settings - Fork 5
/
cpdir.php
46 lines (42 loc) · 1.5 KB
/
cpdir.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
<?php
if (isset($_GET['dir']) && isset($_GET['dirName']) && isset($_GET['copypath'])) {
$dir = $_GET['dir'];
$copy = $_GET['copypath'];
$dirname = $_GET['dirName'];
$dirpath = "{$dir}/{$dirname}";
$copypath = "{$copy}/{$dirname}";
function is_empty_dir($dirpath) {
if (!is_readable($dirpath))
return null;
$dircontent = scandir($dirpath);
if (count($dircontent) == 2) {
return TRUE;
} else {
return FALSE;
}
}
function recursive_cpdir($dirpath, $copypath) {
if (is_empty_dir($dirpath)) {
//empty dir
mkdir($copypath);
} else {
//directory not empty
mkdir($copypath);
$dirpath_content_scanned = scandir($dirpath);
$count = count($dirpath_content_scanned);
for ($i = 0; $i < $count; $i++) {
$file = $dirpath_content_scanned[$i];
if ($file !== '.' && $file !== '..') {
if (filetype("{$dirpath}/{$file}") === 'dir') {
recursive_cpdir("{$dirpath}/{$file}", "{$copypath}/{$file}");
} else {
copy("{$dirpath}/{$file}", "{$copypath}/{$file}");
}//is file
}
}// end for
}// recursive_cpdir function
}
recursive_cpdir($dirpath, $copypath);
$redirect = dirname($_SERVER['PHP_SELF']) . "/index.php?dir={$dir}";
header("Location:{$redirect}");
}