简体   繁体   中英

php API to upload and download files to Amazon S3

I have a website hosted on amazon. I want my clients to give access to upload files that are already in their amazon s3 space to my s3 space. Is there any php API that supports this functionality?

Amazon actually provides one . And there are lots of examples on the web of using it. Google is your friend.

Amazon have a PHPSDK , check the sample code

// The sample code below demonstrates how Resource APIs work


$aws = new Aws($config);

// Get references to resource objects



$bucket = $aws->s3->bucket('my-bucket');

$object = $bucket->object('image/bird.jpg');

// Access resource attributes


echo $object['LastModified'];

// Call resource methods to take action


$object->delete();

$bucket->delete();

Or use old s3.php for uploading files to s3 bucket. its a single php file named s3.php You just download that and from your code . for more read this .

<?php


if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'YourAccess S3 Key');
if (!defined('awsSecretKey')) define('awsSecretKey', 'Yor Secret Key');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
$s3->putBucket("bucket name", S3::ACL_PRIVATE);

//move the file
if ($s3->putObjectFile("your file name in the server with path", "which bucket ur using (bucket name)", "fine name in s3 server", S3::ACL_PRIVATE)) {

//s3 upload success

}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM