Last active
February 8, 2024 01:08
-
-
Save carlesloriente/70c6691cd8647cfa03bfda0f39cac681 to your computer and use it in GitHub Desktop.
A simple PHP script for upload files to s3 using AWS SDK
This file contains 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
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.notesoncloudcomputing.com/aws/php/2020/01/04/aws-sdk-php-script-upload-to-s3/