Advertisement
Viruthagiri

Untitled

Aug 6th, 2011
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.         <title>S3 tutorial</title>
  6.         <link href="styles3.css" rel="stylesheet" type="text/css">
  7.     </head>
  8.  
  9. <body>
  10.         <?php
  11.             //include the S3 class
  12.             if (!class_exists('S3'))require_once('S3.php');
  13.            
  14.             //AWS access info
  15.             if (!defined('awsAccessKey')) define('awsAccessKey', 'mykeygoeshere');
  16.             if (!defined('awsSecretKey')) define('awsSecretKey', 'mykeygoeshere');
  17.            
  18.             //instantiate the class
  19.             $s3 = new S3(awsAccessKey, awsSecretKey);
  20.            
  21.             //check whether a form was submitted
  22.             if(isset($_POST['Submit'])){
  23.            
  24.             $url = $_POST['link']; #
  25.             $getFile = pathinfo($url);
  26.                 //retreive post variables
  27.                 $fileName = $getFile['filename'];
  28.                 $fileTempName = sha1(microtime().uniqid('',true));
  29.                
  30.                 //create a new bucket
  31.                 $s3->putBucket("mybucketnamegoeshere", S3::ACL_PUBLIC_READ);
  32.                
  33.                 //move the file
  34.                 if ($s3->putObjectFile($fileTempName, "mybucketnamegoeshere", $fileName, S3::ACL_PUBLIC_READ)) {
  35.                     echo "<strong>We successfully uploaded your file.</strong>";
  36.                 }else{
  37.                     echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
  38.                 }
  39.             }
  40.         ?>
  41. <h1>Upload a file</h1>
  42. <p>Please select a file by clicking the 'Browse' button and press 'Upload' to start uploading your file.</p>
  43.     <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  44.       <input type="text" name="link"  size="45" value="">
  45.       <input name="Submit" type="submit" value="Upload">
  46.     </form>
  47. <h1>All uploaded files</h1>
  48. <?php
  49.     // Get the contents of our bucket
  50.     $contents = $s3->getBucket("mybucketnamegoeshere");
  51.     foreach ($contents as $file){
  52.    
  53.         $fname = $file['name'];
  54.         $furl = "http://mybucketnamegoeshere.s3.amazonaws.com/".$fname;
  55.        
  56.         //output a link to the file
  57.         echo "<a href=\"$furl\">$fname</a><br />";
  58.     }
  59. ?>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement