<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>S3 tutorial</title>
        <link href="style.css" rel="stylesheet" type="text/css">
    </head>

<body>
    	<?php
        
			//include the S3 class
			if (!class_exists('S3'))require_once('includes/S3.php');
			
			//AWS access info
			if (!defined('awsAccessKey')) define('awsAccessKey', 'AKIAJVI62E3WWAEQHTEQ');
			if (!defined('awsSecretKey')) define('awsSecretKey', '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');
			
			//instantiate the class
			$s3 = new S3(awsAccessKey, awsSecretKey);
                       /* if ($s3->putBucket('bullszi', S3::ACL_PUBLIC_READ)) {
                            echo "Created bucket {$bucketName}".PHP_EOL;
                        } else {
                            echo "S3::putBucket(): Unable to create bucket (it may already exist and/or be owned by someone else)\n";
                       
                        }*/
                        echo "S3::listBuckets(): ".print_r($s3->listBuckets(), 1)."\n";
			
			//check whether a form was submitted
			if(isset($_POST['Submit'])){
			
				//retreive post variables
				$fileName = $_FILES['theFile']['name'];
				$fileTempName = $_FILES['theFile']['tmp_name'];
                                
                                //$fileTempName = 'S3.php';
                               // echo $fileTempName;exit;
				//echo $fileName;exit;
				//create a new bucket
				//$s3->putBucket("yourbucket", S3::ACL_PUBLIC_READ);
				
				//move the file
                           
				if ($s3->putObjectFile($fileTempName, "www.bullszi.com",'products/'.$fileName, S3::ACL_PUBLIC_READ)) {
					echo "<strong>We successfully uploaded your file.</strong>";
				}else{
					echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
				}
			}
		?>
<h1>Upload a file</h1>
<p>Please select a file by clicking the 'Browse' button and press 'Upload' to start uploading your file.</p>
   	<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
      <input name="theFile" type="file" />
      <input name="Submit" type="submit" value="Upload">
	</form>
<h1>All uploaded files</h1>
<?php
	// Get the contents of our bucket
	$contents = $s3->getBucket("www.bullszi.com");
        
       
        //print '<pre />';print_r($contents);
        
       // echo $contents['products/small/123.jpg']['name'];
        //exit;
        
        //$contents = $s3->getObject("www.bullszi.com",'');
	foreach ($contents as $file){
	
		$fname = $file['name'];
		$furl = "http://www.bullszi.com.s3.amazonaws.com/".$fname;
		//$s3->deleteObject('www.bullszi.com',$fname);
		//output a link to the file
                echo $furl.'<br />';
		//echo "<a href=\"$furl\"><img src=\"$furl\" alt=\"$fname\" /></a><br />";
	}
        /*$contents1 = $s3->getBucket("www.bullszi.com");
        foreach ($contents1 as $file){
	
		$fname = $file['name'];
		$furl = "http://www.bullszi.com.s3.amazonaws.com/".$fname;
		
		//output a link to the file
		echo "<a href=\"$furl\"><img src=\"$furl\" alt=\"$fname\" /></a><br />";
	}*/
        
        $contents = $s3->getBucket("www.bullszi.com");
        
        
?>
</body>
</html>