This is the source code to backup/download Amazon S3 Bucket’s multimedia files to other server by PHP…
here $bucketurl is XML url of Amazon S3 bucket with full ACL.
$folder is path of the server where S3 files to store.
This script will download all files in Amazon bucket to other server
<?php
/* url for Amazon Bucket */
$bucketurl = “http://BUCKETNAME.s3.amazonaws.com/”;
$xml = file_get_contents($bucketurl);
/* folder name for server */
$folder = “/var/www/html/BUCKETNAME/”;
$content = getTag( ‘Key’, $xml );
foreach($content as $file)
{
exec( “wget -O “.$folder.$file.” “.$bucketurl.$file );
}
/* function to get node from Amazon Bucket XML */
function getTag( $tag, $xml )
{
$tag = preg_quote($tag);
preg_match_all(‘{<‘.$tag.'[^>]*>(.*?)</’.$tag.’>}’, $xml, $matches, PREG_PATTERN_ORDER);
return $matches[1];
}
?>
2 Responses to Backup Amazon S3 with PHP
Leave a Reply
You must be logged in to post a comment.
I’m really thankful towards the author with this post for making this lovely and informative article live here for us. We really appreciate ur effort. Maintain the nice work. . . .
Excellent read, I simply passed this onto a colleague who had been doing a little research on that. And he actually bought me lunch because I discovered it for him smile So ok , i’ll rephrase that: Many thanks lunch!