[英]php API to upload and download files to Amazon S3
我在亞馬遜上有一個網站。 我希望我的客戶能夠訪問已經在他們的亞馬遜s3空間中的文件上傳到我的s3空間。 有沒有支持此功能的php API?
亞馬遜實際提供一個 。 網上有很多使用它的例子。 谷歌是你的朋友。
亞馬遜有一個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文件你只需從你的代碼中下載它。 更多閱讀本文 。
<?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.