简体   繁体   English

php API将文件上传和下载到Amazon S3

[英]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. 我希望我的客户能够访问已经在他们的亚马逊s3空间中的文件上传到我的s3空间。 Is there any php API that supports this functionality? 有没有支持此功能的php API?

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 亚马逊有一个PHPSDK ,检查示例代码

// 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. 或者使用旧的s3.php将文件上传到s3存储桶。 its a single php file named s3.php You just download that and from your code . 它是一个名为s3.php的php文件你只需从你的代码中下载它。 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

}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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