website/public/API/getFile.php

38 lines
1.2 KiB
PHP
Raw Normal View History

2021-05-13 22:32:19 +02:00
<?php
include("./lib/config.php");
require 'vendor/autoload.php';
$s3Client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'endpoint' => $S3Server,
'use_path_style_endpoint' => true,
'credentials' => [
'key' => $S3AccessKey,
'secret' => $S3SecretKey,
],
]);
// Get a command object from the client
$command = $s3Client->getCommand('GetObject', [
'Bucket' => $S3BucketName,
'Key' => $_GET["filename"]
]);
// Create a pre-signed URL for a request with duration of 10 miniutes
2021-05-13 23:07:03 +02:00
$presignedRequest = $s3Client->createPresignedRequest($command, '60 minutes');
2021-05-13 22:32:19 +02:00
// Get the actual presigned-url
2021-05-13 23:07:03 +02:00
$downloadURL = (string) $presignedRequest->getUri();
2021-09-26 00:05:13 +02:00
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $downloadURL);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt ($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true);
$content = curl_exec ($curl);
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
header('Content-Type: ' . $contentType);
echo($content);