-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_sender.php
74 lines (63 loc) · 1.75 KB
/
file_sender.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
<?php
/**
* file sender
*
* 2013-05-06 create by csk83
*/
define('THE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR);
require THE_DIR.'file_config.php';
require THE_DIR.'file_snoopy.php';
if(file_exists(PFSR_SENDER_PID)){
exit;
}else{
file_put_contents(PFSR_SENDER_PID, time());
}
$dir = PFSR_SENDER_DIR;
sendDirFiles($dir);
unlink(PFSR_SENDER_PID);
function sendDirFiles($dir){
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file == '.' || $file == '..'){
}else{
$file_type = filetype($dir.$file);
if($file_type == 'dir'){
sendDirFiles($dir.$file);
}else if($file_type == 'file'){
$r = sendFile($dir.$file);
if($r === true)
rename($dir.$file, PFSR_SENDER_SUCCESS_DIR.$file);
else{
}
}
}
}
closedir($dh);
}else{
return false;
}
}else{
return false;
}
return true;
}
function sendFile($file){
$submit_url = PFSR_SENDER_URL;
$file_md5 = md5_file($file);
$submit_vars = array(
'k' => $file_md5,
's' => md5(PFSR_SIGN_KEY . $file_md5 . PFSR_SIGN_KEY)
);
$submit_files = array('f' => $file);
$snoopy = new Snoopy();
$snoopy->set_submit_multipart();
$snoopy->submit($submit_url, $submit_vars, $submit_files);
$r = $snoopy->results;
$r = trim($r);
if($r == 'SUCCESS'){
return true;
}else{
return $r;
}
}