Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!class_exists('S3')) require_once 'S3.php';
- // AWS access info
- if (!defined('awsAccessKey')) define('awsAccessKey', '...');
- if (!defined('awsSecretKey')) define('awsSecretKey', '...');
- // Check for CURL
- S3::setAuth(awsAccessKey, awsSecretKey);
- $bucket = 'my_bucket';
- $path = ''; // Can be empty ''
- $lifetime = 20; // Period for which the parameters are valid
- $maxFileSize = (1024 * 1024 * 50); // 50 MB
- $metaHeaders = array('uid' => 123);
- $requestHeaders = array(
- 'Content-Type' => 'application/octet-stream',
- 'Content-Disposition' => 'attachment; filename=${filename}'
- );
- $params = S3::getHttpUploadPostParams(
- $bucket,
- $path,
- S3::ACL_PUBLIC_READ,
- $lifetime,
- $maxFileSize,
- 200, // Or a URL to redirect to on success
- $metaHeaders,
- $requestHeaders,
- false // False since we're not using flash
- );
- $uploadURL = 'https://' . $bucket . '.s3.amazonaws.com/';
- ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>S3 Form Upload</title>
- </head>
- <body>
- <form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
- <?php
- foreach ($params as $p => $v)
- echo " <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
- ?>
- <input type="file" name="file" /> <input type="submit" value="Upload" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement