-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathups3.php
62 lines (50 loc) · 1.66 KB
/
ups3.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
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// DIRETORIO QUE SERÁ FEITO UPLOAD
$diretorio = '/Users/rabelo/www/teste';
// PARTE A SER DESCARTADA AO CRIAR ESTRUTURA NO S3
$remove_estrutura_aws = "/Users/rabelo/www/";
// INFORMAÇOES S3.
$aws_key = 'test';
$aws_secret = 'test';
$aws_region = 'us-east-1';
$aws_bucket = 'tag';
$aws_endpoint = 'http://s3.localhost.localstack.cloud:4566';
$s3Client = new S3Client([
'credentials' => [
'key' => $aws_key,
'secret' => $aws_secret,
],
'region' => $aws_region,
'use_path_style_endpoint' => true,
'endpoint' => $aws_endpoint,
]);
if (!is_dir($diretorio)) {
echo "O diretório especificado não existe.\n";
return;
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($diretorio));
$local = 'log.txt';
$log = fopen($local, "a+");
foreach ($iterator as $arquivo) {
if ($arquivo->isFile()) {
$file_Path = $arquivo->getPathname();
$key = str_replace($remove_estrutura_aws,'',$arquivo->getPathname());
try {
$result = $s3Client->putObject([
'Bucket' => $aws_bucket ,
'Key' => $key,
'Body' => fopen($file_Path, 'r'),
]);
echo "sucesso: " . $result->get('ObjectURL')."\n";
$textoLog = basename($arquivo->getPathname())."|".$arquivo->getPathname()."|".$result->get('ObjectURL')."\n";
fwrite($log, $textoLog);
} catch (Aws\S3\Exception\S3Exception $e) {
echo "Erro ao enviar arquivo\n";
echo $e->getMessage();
}
}
}
fclose($log);
exit();