Amazon S3 is storage for the Internet. Amazon provides the space for large amount of data storing.The data will be upload from your site but store on amazon, your site just save the name of file.From file name data also retrieve on your site from amazon.
For implementation on website just follow the following step.
1. Download the code from following and extract.
2. There are three file containing style.css, s3.php and page.php. Don't touch other files only open page.php
and define access, secret key . Following red word, you need to change with your given Amazon keys.
if (!defined('awsAccessKey')) define('awsAccessKey', 'CHANGE THIS');
if (!defined('awsSecretKey')) define('awsSecretKey', 'CHANGE THIS TOO');
3. You need to change your bucket name in follwing code. Write your bucket name on place of yourbucket.
remember yourbucket is your object and you can only made 100 bucket in one account.
$s3->putBucket("yourbucket", S3::ACL_PUBLIC_READ);
4. Only Change these avobe red highlighted words and your task is complete.
5. For uploading change in following code.
if(isset($_POST['Submit'])){
$fileName = $_FILES['filenamechange']['name'];
$fileTempName = $_FILES['filenamechange']['tmp_name'];
$s3->putBucket("yourbucket", S3::ACL_PUBLIC_READ);
if ($s3->putObjectFile($fileTempName, "yourbucket", $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>";
}
}
6. Retrieve data from following code.
$contents = $s3->getBucket("yourbucket");
foreach ($contents as $file){
$fname = $file['name'];
$furl = "http://yourbucket.s3.amazonaws.com/".$fname;
echo "<a href=\"$furl\">$fname</a><br />";
}
This is the way implementing amazon S3 services. Remember only you need to amazon S3 Access and Secret keys.
No comments:
Post a Comment