forked from az-neo/auto-backup-folder-to-S3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
86 lines (68 loc) · 2.3 KB
/
index.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
$myfile = fopen("log.txt", "r");
while ($line = fgets($myfile)) {
// <... Do your work with the line ...>
$data[] = $line;
}
//$myfile_aws = fopen("logfile_aws.txt", "w");
$myfile_aws = fopen("logfile_aws.txt", "r");
while ($line_aws = fgets($myfile_aws)) {
// <... Do your work with the line ...>
$data_aws[] = $line_aws;
}
//fwrite($myfile_aws, $txt);
fclose($myfile_aws);
fclose($myfile);
// echo "<pre>";
// var_dump($data);
// var_dump($data_aws);
// echo "</pre>";
function findMissing( $data, $data_aws='', $n, $m=''){
for ( $i = 0; $i < $n; $i++)
{
//$myfile_aws_write_log = fopen("logfile_aws.txt", "w");
if($data_aws != NULL){
if (in_array($data[$i], $data_aws)){
Continue;
}
else{
$new_data[] = $data[$i];
}
}
else{
$myfile_aws_write_log = "logfile_aws.txt";
file_put_contents($myfile_aws_write_log, $data[$i],FILE_APPEND);
// $myfile_aws_write_log = fopen("logfile_aws.txt", "w");
// fwrite($myfile_aws_write_log, $data[$i]);
// fclose($myfile_aws_write_log);
}
}
require("app/start.php");
/*echo "<pre>";
var_dump($new_data);
echo "</pre>";
die();*/
if(isset($new_data)){
foreach($new_data AS $new){
$files = explode(",",$new);
/*Upload a publicly accessible file. The file size and type are determined by the SDK.*/
try {
$s3->putObject([
'Bucket' => 'pnl-employee-document',
'Key' => $files[3],
'Body' => fopen($files[2],'r'),
'ACL' => 'public-read',
]);
}catch (Aws\S3\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
}
$myfile_aws_write_log = "logfile_aws.txt";
file_put_contents($myfile_aws_write_log, $new,FILE_APPEND);
}
}
}
// Driver code
$n = count($data);
$m = isset($data_aws)?count($data_aws):'';
findMissing($data, $data_aws, $n, $m);
?>