Skip to content

Instantly share code, notes, and snippets.

@alfrekjv
Created January 16, 2012 05:01
Show Gist options
  • Save alfrekjv/1619151 to your computer and use it in GitHub Desktop.
Save alfrekjv/1619151 to your computer and use it in GitHub Desktop.
Upload a file on Amazon S3
<?php
// Upload a file on Amazon S3
require_once '/vendor/AWSSDKforPHP/sdk.class.php';
$file = $_FILES['file'];
$s3 = new AmazonS3($access, $secret); // your amazon s3 credentials.
$awsResponse = $s3->create_object($bucketName, $file['name'], array(
'fileUpload' => fopen($file['tmp_name'], 'r'),
'contentType' => $file['type'],
'length' => $file['size'],
'acl' => AmazonS3::ACL_PRIVATE,
'storage' => AmazonS3::STORAGE_REDUCED
));
if ($awsResponse->isOK()) {
echo "File uploaded.";
} else {
echo "upload failed. please try again.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment