Skip to content

Instantly share code, notes, and snippets.

@MiniCodeMonkey
Created August 6, 2013 15:42
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 MiniCodeMonkey/6165663 to your computer and use it in GitHub Desktop.
Save MiniCodeMonkey/6165663 to your computer and use it in GitHub Desktop.
<?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