Skip to content

Instantly share code, notes, and snippets.

@Wysie
Last active January 7, 2025 21:32
Show Gist options
  • Save Wysie/03934b6a79a715772abd to your computer and use it in GitHub Desktop.
Save Wysie/03934b6a79a715772abd to your computer and use it in GitHub Desktop.

Revisions

  1. Wysie revised this gist Sep 28, 2014. No changes.
  2. Wysie revised this gist Sep 28, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //Using S3.php from https://github.com/tpyo/amazon-s3-php-class
    //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
    @@ -17,8 +17,8 @@
    if(in_array($extension, $allowed)) {
    $awsAccessKey = get_app_info('s3_key');
    $awsSecretKey = get_app_info('s3_secret');
    $bucketName = 'co.mailworthy.media';
    $endpoint = 's3-ap-southeast-1.amazonaws.com';
    $bucketName = 'BUCKETNAME'; //Change accordingly
    $endpoint = 's3-ap-southeast-1.amazonaws.com'; //Change accordingly
    $s3 = new S3($awsAccessKey, $awsSecretKey, false, $endpoint);
    $s3Filename = $time.baseName($fileName);

  3. Wysie created this gist Sep 28, 2014.
    34 changes: 34 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    //Using S3.php from https://github.com/tpyo/amazon-s3-php-class
    //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 = 'co.mailworthy.media';
    $endpoint = 's3-ap-southeast-1.amazonaws.com';
    $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;
    ?>