Untitled

Wed Mar 2

AmazonS3 SDK sample

//AmazonSDK
App::import('Vendor','include_path');
App::import('Vendor','aws',array('file'=>'sdk.class.php'));

$s3 = new AmazonS3();
$s3->set_cache_config('apc');


//file download
$s3_object_headers = $s3->cache( $cache_time )->get_object_headers($s3_backet_name,$s3_file_path);

if($s3_object_headers->isOK()){
	$s3_object_last_modified = strtotime($s3_object_headers->header['last-modified']);
	$ec2_file_last_modified =  filemtime($ec2_file_path);
	if( $s3_object_last_modified >= $ec2_file_last_modified) {
		$response = $s3->get_object($s3_backet_name,$s3_file_path,array('fileDownload'=>$ec2_file_path));
	}
}

//file upload
$response = $s3->create_object($s3_backet_name,$s3_object_name,array('fileUpload'=>$ec2_file_path));