Location: PHPKode > scripts > Amazon s3 POST flash uploader > s3_flash_uploader.php
<?php 
/*

@copyright : Copyright 2012 sreeblog.net
@license  : http://opensource.org/licenses/mit-license.php
 
*/

 error_reporting(-1);


 require 'PostPolicy.php';

/* 
   Configure s3 varables 
   enter aws id,secret key and buckey you wanted to upload these are mandatery
*/

$AWS_id='YOUR_AWS_ID';
$AWS_key_secret = 'YOUR_KEY';
$AWS_bucket = 'YOUR_BUCKET';

/* 
  Enter Optional setting
*/

// subfolder within the bucket
$AWS_path_to_file="";
$AWS_acl="public-read";
$success_action_redirect='201';
$content_type="application/octet-stream";
// default up to 5 GB 
$content_max_length="5000000000";
$success_action_redirect = '201';

// Create a new POST policy document
$AWS_s3policy = new Aws_S3_PostPolicy($AWS_id, $AWS_key_secret, $AWS_bucket, 86400);
$AWS_s3policy->addCondition('', 'acl', $AWS_acl)
         ->addCondition('', 'bucket', $AWS_bucket)
         ->addCondition('starts-with', '$key', "$AWS_path_to_file")
         // important parameter flash silently sending this  via POST, which  fixes 403 error 
         ->addCondition('starts-with', '$Filename', "")
         ->addCondition('starts-with', '$Content-Type', '')
         ->addCondition('', 'success_action_redirect', $success_action_redirect)
         ->addCondition('content-length-range', '0',$content_max_length);

?>

<html>
<head>
<body>
<!--  swfupload.js is required  which can be downloaded from http://code.google.com/p/swfupload/downloads/list -->
<script type="text/javascript" src="swfupload.js"></script>
<script type="text/javascript">
			     var swfu;
                             window.onload = function() {
                             var settings = {
                             flash_url : "swfupload.swf",
                             upload_url: "http://<?php echo $AWS_bucket ?>.s3.amazonaws.com/",
			     /* Important parameter to Fix error max upload per requests */
                             file_post_name : "file",
			    
                     /* Send additional post parameters which amazon expects during upload */
                             post_params: {
                              "key" : "<?php echo $AWS_path_to_file ?>${filename}",
                              "AWSAccessKeyId" : "<?php echo $AWS_s3policy->getAwsAccessKeyId() ?>", 
                              "acl" : "<?php echo $AWS_s3policy->getCondition('acl') ?>",
                              "success_action_redirect" : "<?php echo $success_action_redirect ?>",
                              "policy" : "<?php echo $AWS_s3policy->getPolicy(true) ?>",
                              "signature" : "<?php echo $AWS_s3policy->getSignedPolicy() ?>",
                              "Content-Type" : "<?php echo $content_type ?>"
                            },
                            file_size_limit : "5000 MB",
                            file_types : "*.*",
                            file_types_description : "All Files",
                            file_upload_limit : "*" ,
                            file_queue_limit : "*",
		      	    debug: false,
                     // Button settings
                   	    button_image_url: "selectFileButton.png",
                     	    button_width: "100",
                            button_height: "39",
                            button_placeholder_id: "flashUpload",
                     	    button_text_left_padding: 12,
                     	    button_text_top_padding: 5,
                            button_action : -101,
                            file_queued_handler : onFileSelect,
                            upload_progress_handler : onUploadProgress,
                            upload_success_handler : onUploadSuccess,
                            file_queue_error_handler : onFileQueueError,
                            upload_error_handler : onFileUploadError
                     };
                     swfu = new SWFUpload(settings);
                    };
               function onFileSelect(file) {
                var filename = document.getElementById("fileName");
                filename.innerHTML = file.name;

                var progressbar = document.getElementById("progressBar");
                progressbar.innerHTML = "";
                var progresssStatus = document.getElementById("progressStatus");
                progresssStatus.innerHTML = "<span style=\"color:orange\">Queued</span>";
                swfu.startUpload();
             }
	function onUploadProgress(file, bytesLoaded, bytesTotal) {
                var progresssStatus = document.getElementById("progressStatus");
                progresssStatus.innerHTML = "<span style=\"color:orange\">Pending</span>";
                prog = Math.round(300*(bytesLoaded/bytesTotal));
                progbar = "<div style=\"background-color: green; height: 5px; width: " + prog + "px\"/>";
                var progressbar = document.getElementById("progressBar");
                progressbar.innerHTML = progbar;
        }
        function onUploadSuccess(file,serverData) {
                var progresssStatus = document.getElementById("progressStatus");
                progresssStatus.innerHTML = "<span style=\"color:green\">Completed</span>";
	
         }
        function onFileQueueError(file, errorCode, message) {
		
               var progresssStatus = document.getElementById("progressStatus");
                var err="<span style=\"color:red\">" + message + "</span>";
                progresssStatus.innerHTML = err;
        }
        function onFileUploadError(file, errorCode, message) {
               var progresssStatus = document.getElementById("progressStatus");
                var err="<span style=\"color:red\">" + message + "</span>";
                progresssStatus.innerHTML = err;
        }

</script>
</head>
<body>
<div>
<div id="fileProgress" style="border: black 1px solid; width:300px; height:70px;float:left">
    <div id="fileName" style="text-align:center; margin:5px; font-size:15px; width:290px; height:25px; overflow:hidden"></div>
   <div id="progressBar" style="width:300px;height:5px;background-color:#CCCCCC"></div>
   <div id="progressStatus" style="width:300px;height:5px;"></div>
</div>
<div style="width:100px;height:40px;margin-left:5px;float:left">
<span id="flashUpload" />
</div> 
</div> 
</body>
</html>

Return current item: Amazon s3 POST flash uploader