Last active
          January 7, 2025 21:32 
        
      - 
      
 - 
        
Save Wysie/03934b6a79a715772abd to your computer and use it in GitHub Desktop.  
    Upload to Amazon S3 Instead of Server for Sendy Email Image Uploads
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //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; | |
| ?> | 
I have a version that uses AWS SDK directly, and a Docker based setup for deploying to Heroku.
Here's the file: https://github.com/sagararyal/sendy-on-heroku/blob/main/overrides/includes/create/upload.php
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Does this work in 2024? :) Thanks!