diff options
author | Marcos Araujo Sobrinho <marcos.sobrinho@truckpad.com.br> | 2017-11-14 16:12:52 -0200 |
---|---|---|
committer | Marcos Araujo Sobrinho <marcos.sobrinho@truckpad.com.br> | 2017-11-14 16:12:52 -0200 |
commit | a155254c50536a3cd2c70441ad147524e537ff1f (patch) | |
tree | c4308d6048fb19b8f0b410632e5cfd8bc075b7d1 /backend/php-s3/index.php | |
parent | 48913bf78706f5926f8169906d79618ffcbd1299 (diff) | |
download | wwwsqldesigner-a155254c50536a3cd2c70441ad147524e537ff1f.zip wwwsqldesigner-a155254c50536a3cd2c70441ad147524e537ff1f.tar.gz wwwsqldesigner-a155254c50536a3cd2c70441ad147524e537ff1f.tar.bz2 |
AWS S3 Support
Diffstat (limited to 'backend/php-s3/index.php')
-rw-r--r-- | backend/php-s3/index.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/backend/php-s3/index.php b/backend/php-s3/index.php new file mode 100644 index 0000000..71877ca --- /dev/null +++ b/backend/php-s3/index.php @@ -0,0 +1,42 @@ +<?php + $access_key = $_ENV['ACCESS_KEY']; + $secret_key = $_ENV['SECRET_KEY']; + $bucket = $_ENV['BUCKET']; + $path = 'schemas'; + if (!$access_key || !$secret_key || !$bucket) { + header("HTTP/1.0 501 Credentials not provided!"); + return; + } + + include('amazon-s3-php/src/S3.php'); + $client = new S3($access_key, $secret_key, "s3-us-west-2.amazonaws.com"); + + $a = (isset($_GET["action"]) ? $_GET["action"] : false); + switch ($a) { + case "list": + $response = $client->getBucket($bucket); + foreach ($response->body->Contents as $content) { + $key = $content->Key; + if (0 === strpos($key, $path.'/') && $key != $path.'/') + echo substr($key, strlen($path)+1)."\n"; + } + break; + case "save": + $keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : ""); + $data = file_get_contents("php://input"); + $client->putObject($bucket, $path.'/'.$keyword, $data, array('Content-Type' => 'text/xml')); + header("HTTP/1.0 201 Created"); + break; + case "load": + $keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : ""); + $file = $client->getObject($bucket, $path.'/'.$keyword); + if ($file->body) { + header("Content-type: text/xml"); + echo $file->body; + } else { + header("HTTP/1.0 404 Not Found"); + } + break; + default: header("HTTP/1.0 501 Not Implemented"); + } +?> |