<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Description of AmazonS3
 *
 * @author wahyu widodo
 */
 
 include("./vendor/autoload.php");
 
 use Aws\S3\S3Client;
 
 class Aws3{
	
	private $S3;

	public function __construct(){
		$this->S3 = S3Client::factory([
			'key' => 'AKIAZLDAZMGCID46MGHB',
			'secret' => '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',
			'region' => 'ap-southeast-1',
			'Bucket'=> 'makeabl-data'
		]);
	}	
	
	public function addBucket($bucketName){
		$result = $this->S3->createBucket(array(
			'Bucket'=>$bucketName,
			'LocationConstraint'=> 'ap-southeast-1'));
		return $result;	
	}
	
	public function sendFile($bucketName, $filename){
		$result = $this->S3->putObject(array(
				'Bucket' => $bucketName,
				'Key' => $filename['name'],
				'SourceFile' => $filename['tmp_name'],
				'ContentType' => 'image/png',
				'StorageClass' => 'STANDARD',
				'ACL' => 'public-read'
		));
		return $result['ObjectURL']."\n";
	}		
	 

 	public function sendFileLink($bucketName, $Key, $file_Path){
		$result = $this->S3->putObject(array(
				'Bucket' => $bucketName,
				'Key' => $Key,
				'Body' => fopen($file_Path, 'r'),
				'ACL' => 'public-read'
		));
		return $result['ObjectURL']."\n";
	}		
	 
 }