Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upload to Amazon S3 Instead of Server for Sendy Email Image Uploads
//Using S3.php from https://github.com/tpyo/amazon-s3-php-class. Place it in includes/helpers
//Replaces Sendy's includes/create/upload.php
<?php
include('../functions.php');
include('../login/auth.php');
require_once('../helpers/S3.php');
//Init
$file = $_FILES['file']['tmp_name'];
$fileName = $_FILES['file']['name'];
$extension_explode = explode('.', $fileName);
$extension = $extension_explode[count($extension_explode)-1];
$time = time();
$allowed = array("jpeg", "jpg", "gif", "png");
if(in_array($extension, $allowed)) {
$awsAccessKey = get_app_info('s3_key');
$awsSecretKey = get_app_info('s3_secret');
$bucketName = 'BUCKETNAME'; //Change accordingly
$endpoint = 's3-ap-southeast-1.amazonaws.com'; //Change accordingly
$s3 = new S3($awsAccessKey, $awsSecretKey, false, $endpoint);
$s3Filename = $time.baseName($fileName);
if ($s3 -> putObject($s3->inputFile($file), $bucketName, $s3Filename, S3::ACL_PUBLIC_READ)) {
$array = array(
'filelink' => 'http://'.$endpoint.'/'.$bucketName.'/'.$s3Filename
);
echo stripslashes(json_encode($array));
}
else exit;
}
else exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.