Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Forked from cameronjacobson/form.php
Created April 21, 2014 17:15
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 xeoncross/11149279 to your computer and use it in GitHub Desktop.
Save xeoncross/11149279 to your computer and use it in GitHub Desktop.
<?php
if(isset($_GET['success'])){
echo 'done';
exit;
}
$policy = base64_encode(str_replace(array("\r","\n"),"",'{ "expiration": "2023-01-01T12:00:00.000Z", "conditions": [
{"acl": "public-read" },
{"bucket": "MYBUCKET" },
["starts-with", "$key", "UUID/"],
{"success_action_redirect": "http://MYHOSTNAME/form.php?success=true"},
["starts-with", "$Content-Type", ""],
["content-length-range", 0, 200000]
] }'));
$key = 'MY_SECRET_ACCESS_KEY';
$signature = base64_encode(hash_hmac('sha1', $policy, $key, true));
?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head><body>
<form method="POST" enctype="multipart/form-data" action="https://MYBUCKET.s3.amazonaws.com/">
<input type="hidden" name="AWSAccessKeyId" value="MY_ACCESS_KEY_ID" />
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="key" value="UUID/${filename}" />
<input type="hidden" name="policy" value='<?php echo $policy; ?>' />
<input type="hidden" name="signature" value="<?php echo $signature; ?>" />
<input type="hidden" name="success_action_redirect" value="http://MYHOSTNAME/form.php?success=true" />
<input type="hidden" name="Content-Type" value="image/png" />
<input type="file" name="file" />
<input type="submit" value="submit">
</form>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment