Skip to content

Instantly share code, notes, and snippets.

@borisguery
Last active January 4, 2016 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borisguery/8559635 to your computer and use it in GitHub Desktop.
Save borisguery/8559635 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
require __DIR__.'/../vendor/autoload.php';
use Aws\S3\S3Client;
$options = getopt('a:s:d:b:c:vh');
if (isset($options['h'])) {
printf("usage: %s -v(erbose) -a(ccess-key) value, -s(ecret-key) value -d(irectory) value -b(ucket) value -c(oncurrency) value -h(elp)\n", $argv[0]);
exit(1);
}
$verbose = isset($options['v']) ? true : false;
$awsAccessKey = isset($options['a']) ? $options['a'] : null;
$awsSecretKey = isset($options['s']) ? $options['s'] : null;
$dir = isset($options['d']) ? $options['d'] : null;
$bucket = isset($options['b']) ? $options['b'] : null;
$concurrency = isset($options['c']) ? $options['c'] : 5;
foreach (array($awsAccessKey, $awsSecretKey, $dir, $bucket) as $value) {
if (empty($value)) {
printf("error: some options are missing, mandaroty are access_key, secret_key, directory and bucket\n");
exit(1);
}
}
$client = S3Client::factory(
array(
'key' => $awsAccessKey,
'secret' => $awsSecretKey,
)
);
$client->setRegion('eu-west-1');
$client->registerStreamWrapper();
printf("AWS S3 Mass Import\n");
printf("------------------\n\n");
$client->uploadDirectory(
$dir,
$bucket,
'',
array(
'params' => array('ACL' => 'public-read'),
'concurrency' => $concurrency,
'debug' => $verbose,
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment