如何使用第三方&x27;Amazon S3 PHP类';要公开存储桶中的每个文件?
我正在尝试使用第三方将bucket中的每个文件公开,但似乎无法使用acl控制策略-我尝试了以下代码但未成功:如何使用第三方&x27;Amazon S3 PHP类';要公开存储桶中的每个文件?,php,amazon-s3,amazon,acl,public,Php,Amazon S3,Amazon,Acl,Public,我正在尝试使用第三方将bucket中的每个文件公开,但似乎无法使用acl控制策略-我尝试了以下代码但未成功: if (!class_exists('S3')) require 's3/S3.php'; // AWS access info if (!defined('awsAccessKey')) define('awsAccessKey', $as3key); if (!defined('awsSecretKey')) define('awsSecretKey', $
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";
}
}
}
}
有人能帮忙吗?要允许公众访问您的文件,您应该通过以下方式发送:
$file_upload_response = $s3->create_object($bucket, $file_on_amazon_s3, array (
'fileUpload' => $file_attach,
'acl' => AmazonS3::ACL_PUBLIC
));
如果要在上载后更改为公共访问:
$s3_response = $s3->set_object_acl($bucket,
$file_on_amazon_s3,
AmazonS3::ACL_PUBLIC);
要允许公众访问您的文件,您应通过以下方式发送:
$file_upload_response = $s3->create_object($bucket, $file_on_amazon_s3, array (
'fileUpload' => $file_attach,
'acl' => AmazonS3::ACL_PUBLIC
));
如果要在上载后更改为公共访问:
$s3_response = $s3->set_object_acl($bucket,
$file_on_amazon_s3,
AmazonS3::ACL_PUBLIC);
如果要将文件公开,请在权限数组中将uri设置为“”,并将权限设置为“读取” 如果(!class_存在('S3'))需要'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" => "http://acs.amazonaws.com/groups/global/AllUsers", "permission" => "READ"
);
// Then update the policy using the modified $acp array:
if (S3::setAccessControlPolicy($bucket, $fname, $acp)) {
echo $fname . "Policy updated";
}
}
}
}
如果要将文件公开,请在权限数组中将uri设置为“”,并将权限设置为“读取” 如果(!class_存在('S3'))需要'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" => "http://acs.amazonaws.com/groups/global/AllUsers", "permission" => "READ"
);
// Then update the policy using the modified $acp array:
if (S3::setAccessControlPolicy($bucket, $fname, $acp)) {
echo $fname . "Policy updated";
}
}
}
}
您好,我正在尝试在程序上传后更改策略。此代码是否仍适用于最新的AWS代码库(1.5.3版)?它只在1.5.0.1版上对我有效,不再适用于最新版本。您好,我正在尝试在程序上载策略后更改策略。此代码是否仍适用于最新的AWS代码库(1.5.3版)?它只在1.5.0.1上对我有效,不再适用于最新版本。