我尝试使用第三方Amazon S3 PHP Class来使bucket中的每个文件都是公共的,但似乎无法弄清楚acl控制策略-我尝试了以下代码,但没有成功:
if (!class_exists('S3')) require 's3/S3.php';
// AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', $as3key);
if (!defined('awsSecretKey')) define('awsSecretKey', $assecretkey);
$s3 = new S3(awsAccessKey, awsSecretKey);
$bucket = ltrim($_POST['bucket']);
$policy = ltrim($_POST['policy']);
if (($contents = $s3->getBucket($bucket)) !== false) {
foreach ($contents as $object) {
$fname = $object['name'];
$furl = "https://". $bucket . ".s3.amazonaws.com/".rawurlencode($fname);
if (($acp = S3::getAccessControlPolicy($bucket,$fname)) !== false) {
// Here you would modify the $acp array...
// For example, grant access to the S3 LogDelivery system:
$acp["acl"][] = array(
"type" => "Group", "uri" => $fname, "permission" => "FULL_CONTROL"
);
// Then update the policy using the modified $acp array:
if (S3::setAccessControlPolicy($bucket, $fname, $acp)) {
echo $fname . "Policy updated";
}
}
}
}
有人能帮帮忙吗?
2条答案
按热度按时间0mkxixxg1#
要允许公众访问您的文件,您应该通过以下方式发送它们:
如果要在上载后更改为公共访问:
qij5mzcb2#
如果你想公开一个文件,那么在权限数组中设置uri为“http://acs.amazonaws.com/groups/global/AllUsers“,权限为“READ”
如果(!class_exists('S3'))需要“s3/S3.php”;