Skip to content

Instantly share code, notes, and snippets.

@carlesloriente
Last active February 8, 2024 01:08
Show Gist options
  • Save carlesloriente/70c6691cd8647cfa03bfda0f39cac681 to your computer and use it in GitHub Desktop.
Save carlesloriente/70c6691cd8647cfa03bfda0f39cac681 to your computer and use it in GitHub Desktop.
A simple PHP script for upload files to s3 using AWS SDK
<?php
require_once '../private/config.php';
require_once $CONF->private . 'Project.php';
require_once $CONF->lib . 'aws/aws-autoloader.php';
define('AWS_KEY', $CONF->AWS_KEY);
define('AWS_SECRET_KEY', $CONF->AWS_SECRET_KEY);
define('HOST', 'https://s3.amazonaws.com/');
use Aws\S3\S3Client;
// Establish connection with DreamObjects with an S3 client.
$client = S3Client::factory(array(
'base_url' => HOST,
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY,
));
$bucket = 'YOUR-S3-BUCKET';
$keyname = 'FILETOUPLOAD.ext';
$filepath = $keyname;
$acl = 'private';
$client->upload($bucket, $keyname, fopen($filepath, 'r'), $acl);
@carlesloriente
Copy link
Author

carlesloriente commented Jan 5, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment