Created
January 16, 2012 05:01
-
-
Save alfrekjv/1619151 to your computer and use it in GitHub Desktop.
Upload a file on Amazon S3
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 | |
// 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