Advertisement
Guest User

Untitled

a guest
Apr 25th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2.  
  3. if (!class_exists('S3')) require_once 'S3.php';
  4.  
  5. // AWS access info
  6. if (!defined('awsAccessKey')) define('awsAccessKey', '...');
  7. if (!defined('awsSecretKey')) define('awsSecretKey', '...');
  8.  
  9. // Check for CURL
  10.  
  11.  
  12. S3::setAuth(awsAccessKey, awsSecretKey);
  13.  
  14. $bucket = 'my_bucket';
  15. $path = ''; // Can be empty ''
  16.  
  17.  
  18. $lifetime = 20; // Period for which the parameters are valid
  19. $maxFileSize = (1024 * 1024 * 50); // 50 MB
  20. $metaHeaders = array('uid' => 123);
  21. $requestHeaders = array(
  22.     'Content-Type' => 'application/octet-stream',
  23.     'Content-Disposition' => 'attachment; filename=${filename}'
  24. );
  25.  
  26. $params = S3::getHttpUploadPostParams(
  27.     $bucket,
  28.     $path,
  29.     S3::ACL_PUBLIC_READ,
  30.     $lifetime,
  31.     $maxFileSize,
  32.     200, // Or a URL to redirect to on success
  33.     $metaHeaders,
  34.     $requestHeaders,
  35.     false // False since we're not using flash
  36. );
  37.  
  38. $uploadURL = 'https://' . $bucket . '.s3.amazonaws.com/';
  39.  
  40. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  42. <head>
  43.     <title>S3 Form Upload</title>
  44. </head>
  45. <body>
  46.     <form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
  47. <?php
  48.     foreach ($params as $p => $v)
  49.         echo "        <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
  50. ?>
  51.         <input type="file" name="file" />&#160;<input type="submit" value="Upload" />
  52.     </form>
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement