-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmulti-upload.php
More file actions
25 lines (20 loc) · 952 Bytes
/
multi-upload.php
File metadata and controls
25 lines (20 loc) · 952 Bytes
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
<?php
require __DIR__ . '/../vendor/autoload.php';
(Dotenv\Dotenv::create(__DIR__))->load();
$browser = new React\Http\Browser();
$s3 = new Clue\React\S3\S3Client(getenv('S3_KEY'), getenv('S3_SECRET'), getenv('S3_BUCKET'), getenv('S3_REGION'), getenv('S3_ENDPOINT'), $browser);
function loga($msg) {
// prepend message with date/time with millisecond precision
$time = microtime(true);
echo date('Y-m-d H:i:s', (int)$time) . sprintf('.%03d ', ($time - (int)$time) * 1000) . $msg . PHP_EOL;
}
for ($i = 1; isset($argv[$i]); ++$i) {
$url = $argv[$i];
loga('Downloading ' . $url);
$browser->get($url)->then(function (Psr\Http\Message\ResponseInterface $response) use ($url, $s3) {
loga('Downloaded ' . $url . ' (' . $response->getBody()->getSize() . ' bytes)');
$s3->write(basename($url), (string)$response->getBody())->then(function () use ($url) {
loga('Uploaded ' . $url);
});
});
}