Created
August 6, 2013 15:42
-
-
Save MiniCodeMonkey/6165663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$aws_key = '<key>'; | |
$s3_secret = '<secret>'; | |
$bucket_name = '<bucket>'; | |
// Duration before request expires | |
$duration = (60 * 5); // 5 minutes | |
$objectName = $_GET['name']; | |
$mimeType = $_GET['type']; | |
$expires = time() + $duration; | |
$amzHeaders = "x-amz-acl:public-read"; | |
$stringToSign = "PUT\n\n" . $mimeType . "\n" . $expires . "\n" . $amzHeaders . "\n" . "/". $bucket_name ."/" . $objectName; | |
$signature = urlencode(base64_encode(hash_hmac('sha1', $stringToSign, $s3_secret, true))); | |
$url = urlencode('https://'. $bucket_name .'.s3.amazonaws.com/' . $objectName . '?AWSAccessKeyId=' . $aws_key . '&Expires=' . $expires . '&Signature=' . $signature); | |
echo $url; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment