github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/app/lib/plupload-2.1.2/examples/jquery/s3.php (about)

     1  <?php 
     2  /* 
     3  In order to upload files to S3 using Flash runtime, one should start by placing crossdomain.xml into the bucket.
     4  crossdomain.xml can be as simple as this:
     5  
     6  <?xml version="1.0"?>
     7  <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
     8  <cross-domain-policy>
     9  <allow-access-from domain="*" secure="false" />
    10  </cross-domain-policy>
    11  
    12  In our tests SilverLight didn't require anything special and worked with this configuration just fine. It may fail back
    13  to the same crossdomain.xml as last resort.
    14  
    15  !!!Important!!! Plupload UI Widget here, is used only for demo purposes and is not required for uploading to S3.
    16  */
    17  
    18  // important variables that will be used throughout this example
    19  $bucket = 'BUCKET';
    20  
    21  // these can be found on your Account page, under Security Credentials > Access Keys
    22  $accessKeyId = 'ACCESS_KEY_ID';
    23  $secret = 'SECRET_ACCESS_KEY';
    24  
    25  // prepare policy
    26  $policy = base64_encode(json_encode(array(
    27  	// ISO 8601 - date('c'); generates uncompatible date, so better do it manually
    28  	'expiration' => date('Y-m-d\TH:i:s.000\Z', strtotime('+1 day')),  
    29  	'conditions' => array(
    30  		array('bucket' => $bucket),
    31  		array('acl' => 'public-read'),
    32  		array('starts-with', '$key', ''),
    33  		// for demo purposes we are accepting only images
    34  		array('starts-with', '$Content-Type', 'image/'),
    35  		// Plupload internally adds name field, so we need to mention it here
    36  		array('starts-with', '$name', ''), 	
    37  		// One more field to take into account: Filename - gets silently sent by FileReference.upload() in Flash
    38  		// http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTFlash.html
    39  		array('starts-with', '$Filename', ''), 
    40  	)
    41  )));
    42  
    43  // sign policy
    44  $signature = base64_encode(hash_hmac('sha1', $policy, $secret, true));
    45  
    46  ?>
    47  <!DOCTYPE html>
    48  <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
    49  <head>
    50  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    51  
    52  <title>Plupload to Amazon S3 Example</title>
    53  
    54  <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" />
    55  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    56  <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
    57  
    58  <!-- Load plupload and all it's runtimes and finally the UI widget -->
    59  <link rel="stylesheet" href="../../js/jquery.ui.plupload/css/jquery.ui.plupload.css" type="text/css" />
    60  
    61  
    62  <!-- production -->
    63  <script type="text/javascript" src="../../js/plupload.full.min.js"></script>
    64  <script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script>
    65  
    66  <!-- debug 
    67  <script type="text/javascript" src="../../js/moxie.js"></script>
    68  <script type="text/javascript" src="../../js/plupload.dev.js"></script>
    69  <script type="text/javascript" src="../../js/jquery.ui.plupload/jquery.ui.plupload.js"></script>
    70  -->
    71  
    72  </head>
    73  <body style="font: 13px Verdana; background: #eee; color: #333">
    74  
    75  <h1>Plupload to Amazon S3 Example</h1>
    76  
    77  <div id="uploader">
    78      <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
    79  </div>
    80  
    81  <script type="text/javascript">
    82  // Convert divs to queue widgets when the DOM is ready
    83  $(function() {
    84  	$("#uploader").plupload({
    85  		runtimes : 'html5,flash,silverlight',
    86  		url : 'http://<?php echo $bucket; ?>.s3.amazonaws.com/',
    87  		
    88  		multipart: true,
    89  		multipart_params: {
    90  			'key': '${filename}', // use filename as a key
    91  			'Filename': '${filename}', // adding this to keep consistency across the runtimes
    92  			'acl': 'public-read',
    93  			'Content-Type': 'image/jpeg',
    94  			'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',		
    95  			'policy': '<?php echo $policy; ?>',
    96  			'signature': '<?php echo $signature; ?>'
    97  		},
    98  		
    99  		// !!!Important!!! 
   100  		// this is not recommended with S3, since it will force Flash runtime into the mode, with no progress indication
   101  		//resize : {width : 800, height : 600, quality : 60},  // Resize images on clientside, if possible 
   102  		
   103  		// optional, but better be specified directly
   104  		file_data_name: 'file',
   105  
   106  		filters : {
   107  			// Maximum file size
   108  			max_file_size : '10mb',
   109  			// Specify what files to browse for
   110  			mime_types: [
   111  				{title : "Image files", extensions : "jpg,jpeg"}
   112  			]
   113  		},
   114  
   115  		// Flash settings
   116  		flash_swf_url : '../../js/Moxie.swf',
   117  
   118  		// Silverlight settings
   119  		silverlight_xap_url : '../../js/Moxie.xap'
   120  	});
   121  });
   122  </script>
   123  
   124  </body>
   125  </html>