【发布时间】:2016-06-24 18:43:26
【问题描述】:
我有一个托管在亚马逊上的网站。我希望我的客户能够将已经在他们亚马逊 s3 空间中的文件上传到我的 s3 空间。有没有支持这个功能的php API?
【问题讨论】:
我有一个托管在亚马逊上的网站。我希望我的客户能够将已经在他们亚马逊 s3 空间中的文件上传到我的 s3 空间。有没有支持这个功能的php API?
【问题讨论】:
亚马逊实际上是provides one。网上有很多使用它的例子。 Google 是您的朋友。
【讨论】:
亚马逊有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();
或者使用旧的 s3.php 将文件上传到 s3 存储桶。它是一个名为 s3.php 的单个 php 文件 您只需下载它并从您的代码中下载。更多信息请阅读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
}
?>
【讨论】: