-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.php
85 lines (69 loc) · 2.18 KB
/
actions.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
<?
function rpc_hello(){
echo "lettura di d1:" . $_POST["d1"] . "\n";
if( $_POST["d1"] == "ok" ) echo "stabbene!";
else echo "non va bene...";
echo "\n";
}
function rpc_synczip(){
$OUT = "";
chdir(ROOT_SERVER_PATH);
$namefile = $_POST["file"];
$path = $_POST["path"];
$zip = new ZipArchive;
$zip_snapshot_path = ROOT_SERVER_PATH . $namefile;
$extract_to_path = ROOT_SERVER_PATH . $path;
$OUT .= "syncZip: path_zip=$zip_snapshot_path\n";
if( $_POST["multipart"] == FALSE ){
if ($zip->open($zip_snapshot_path) === TRUE) {
$zip->extractTo($extract_to_path);
$zip->close();
$OUT .= "syncZip: extract to $extract_to_path, ok\n";
} else {
$OUT .= "syncZip: extract to $extract_to_path, failed\n";
die($OUT);
}
}
else{ //multipart
$OUT .= "syncZip: multipart extraction...";
$files = scandir(ROOT_SERVER_PATH . $namefile);
foreach ($files as $f) { // per ogni file....
if( strpos($f, '.zip') !== false){ // se è un file zip ....
if ($zip->open(ROOT_SERVER_PATH . "$namefile/$f") === TRUE) { // aprilo...
$zip->extractTo($extract_to_path); // estrailo nella cartella di destinazione
$zip->close(); // chiudilo...
unlink(ROOT_SERVER_PATH . "$namefile/$f"); // cancellalo (alla prossima chiamata PHP prenderà il prossimo)
$OUT .= "syncZip: extract to $extract_to_path part:$namefile/$f, ok\n";
} else {
$OUT .= "syncZip: extract to $extract_to_path part:$namefile/$f, failed\n";
die($OUT);
}
}
}
}
//gestione cancellazione file
chdir( $extract_to_path );
$OUT .= "syncZip: change dir to $extract_to_path\n";
if( file_exists(".todelete") ){
$OUT .= "syncZip: found .todelete ...\n";
$todelete = fopen(".todelete","r");
$deleted = fopen(".deleted", "w");
while( !feof($todelete) ){
$target = trim( fgets($todelete) );
//if( is_file ($target) ) unlink($target);
//if( is_dir($target) ) rmrf($target);
unlink($target);
fwrite($deleted, "$target\n");
// else ignoralo...
}
fclose($file);
fclose($deleted);
unlink(".todelete");
unlink(".deleted");
$OUT .= "syncZip: files deleted, ok\n";
}
else{
$OUT .= "syncZip: not found .todelete, nothing to delete?\n";
}
echo $OUT;
}