Upload and Delete Image from the Amazon S3 Bucket
List of step you need to perform to upload/delete image from the server.
1. Download the ZIP directory from <a href="http://nigsys.in/download_amazons3">here</a>. which contains all the necessary files and library files which help to upload and delete images form the server.
1.1. To download the ZIP file, Please use the httaccess username/password : demo/demo
2. After download and extract the zip, you found a AmazonS3 directory which contains the files.
3. Open the "s3_confing.php" configuration file and put "awsAccessKey" and "awsSecretKey" in the s3_config.php file.
Both the "awsAccessKey" & "awsSecretKey" provided by the Amazon S3 at the time of bucket purchase. "Config File " Code mentioned below:
<?php
// Bucket Name
$bucket = "<Put the name of the bucket Here>";
if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', '<Put Amazon Access key Here>');
if (!defined('awsSecretKey')) define('awsSecretKey', '<Put Amazon Secert key Here>');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
@$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
?>
4. Open the "index.php" file search these lines of code mentioned below and put the proper value in the field:
$amazonUrl = '<Put the amazon url here'; //e.g. s3-ap-southeast-1.amazonaws.com/
$directoryPath = '<put the directory path where you want to upload image>'; //e.g. //cw/imageUpload/
$bucket = '<put the name of the bucket here>';
echo $s3file='https://'.$amazonUrl.$bucket.$directoryPath.$actual_image_name;
5. To delete the image from the Amazon S3 bucket open the delete.php file and do some changes as mentioned below:
<?php
// Bucket Name
$bucket = "<Put the name of the bucket Here>";
if (!class_exists('S3'))require_once('S3.php');
$filename=$_REQUEST['fname'];
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', '<Put Amazon Access key Here>');
if (!defined('awsSecretKey')) define('awsSecretKey', '<Put Amazon Secert key Here>');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
if($s3->deleteObject($bucket, $filename)){
echo 'deleted';
}else{
echo 'no file found';
}
?>
1. Download the ZIP directory from <a href="http://nigsys.in/download_amazons3">here</a>. which contains all the necessary files and library files which help to upload and delete images form the server.
1.1. To download the ZIP file, Please use the httaccess username/password : demo/demo
2. After download and extract the zip, you found a AmazonS3 directory which contains the files.
3. Open the "s3_confing.php" configuration file and put "awsAccessKey" and "awsSecretKey" in the s3_config.php file.
Both the "awsAccessKey" & "awsSecretKey" provided by the Amazon S3 at the time of bucket purchase. "Config File " Code mentioned below:
<?php
// Bucket Name
$bucket = "<Put the name of the bucket Here>";
if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', '<Put Amazon Access key Here>');
if (!defined('awsSecretKey')) define('awsSecretKey', '<Put Amazon Secert key Here>');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
@$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
?>
4. Open the "index.php" file search these lines of code mentioned below and put the proper value in the field:
$amazonUrl = '<Put the amazon url here'; //e.g. s3-ap-southeast-1.amazonaws.com/
$directoryPath = '<put the directory path where you want to upload image>'; //e.g. //cw/imageUpload/
$bucket = '<put the name of the bucket here>';
echo $s3file='https://'.$amazonUrl.$bucket.$directoryPath.$actual_image_name;
5. To delete the image from the Amazon S3 bucket open the delete.php file and do some changes as mentioned below:
<?php
// Bucket Name
$bucket = "<Put the name of the bucket Here>";
if (!class_exists('S3'))require_once('S3.php');
$filename=$_REQUEST['fname'];
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', '<Put Amazon Access key Here>');
if (!defined('awsSecretKey')) define('awsSecretKey', '<Put Amazon Secert key Here>');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
if($s3->deleteObject($bucket, $filename)){
echo 'deleted';
}else{
echo 'no file found';
}
?>
Comments
Post a Comment