Skip to content

Instantly share code, notes, and snippets.

@cameronjacobson
Created August 20, 2013 04:46
Show Gist options
  • Select an option

  • Save cameronjacobson/6277197 to your computer and use it in GitHub Desktop.

Select an option

Save cameronjacobson/6277197 to your computer and use it in GitHub Desktop.
bare-bones generate temporary access URL to non-public Amazon S3 resource
<?php
$key = 'SECRET_ACCESS_KEY_ID';
$accesskeyid='ACCESS_KEY_ID';
$expires = time()+60; // URL expires in 60 seconds
$stringtosign = "GET\n\n\n{$expires}\n/BUCKET_NAME/PATH/TO/RESOURCE.EXT";
$signature = urlencode(base64_encode(hash_hmac('sha1',$stringtosign,$key,true)));
echo 'https://BUCKET_NAME.s3.amazonaws.com/PATH/TO/RESOURCE.EXT?'
.'AWSAccessKeyId='.$accesskeyid
.'&Signature='.$signature
.'&Expires='.$expires;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment