Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Upload to Amazon S3 Instead of Server for Sendy Email Image Uploads
//Using S3.php from Place it in includes/helpers
//Replaces Sendy's includes/create/upload.php
$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 = ''; //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.