-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
56 lines (45 loc) · 1.31 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
<?php
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
$config = require('config.php');
$credentials = new Aws\Credentials\Credentials($config['key'], $config['secret']);
$provider = Aws\Credentials\CredentialProvider::fromCredentials($credentials);
$aws = new Aws\Sdk([
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => $provider
]);
$s3 = $aws->createS3();
$app = new Silex\Application();
$app['debug'] = true;
$app->get('/', function() use ($app) {
ob_start();
require('templates/informativo.html');
return ob_get_clean();
});
$app->post('/upload', function (Request $request) use ($app, $s3) {
// get the element by name
$file = $_FILES['file'];
$elementid = $request->get('elementid');
$key = date('YmdHis');
try {
$result = $s3->putObject([
'Bucket' => 'tegra-informativo',
'Key' => $key,
'Body' => fopen($file['tmp_name'], 'r'),
'ACL' => 'public-read',
]);
$actual_link = $result->get('ObjectURL');
} catch (Aws\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
}
return <<<XPTO
<script>
console.log(window.opener);
window.opener.document.setFile('$elementid', '$actual_link');
window.close();
</script>
XPTO;
});
$app->run();
?>