简体   繁体   English

如何使用第三方“ Amazon S3 PHP类”将存储桶中的每个文件公开?

[英]How can I use the 3rd party 'Amazon S3 PHP Class' to make every file in a bucket public?

I am trying to use the 3rd party Amazon S3 PHP Class to make every file in a bucket public, but can't seem to suss out the acl control policy - I have tried the following code without success: 我正在尝试使用第三方Amazon S3 PHP类将存储桶中的每个文件公开,但似乎无法使用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";
            }
            }

        }

    }

Can someone please help? 有人可以帮忙吗?

To allow public access to your files you should send them by this way : 要允许公众访问您的文件,您应该通过以下方式发送文件:

$file_upload_response = $s3->create_object($bucket, $file_on_amazon_s3, array (
                        'fileUpload' => $file_attach,
                        'acl' => AmazonS3::ACL_PUBLIC
                    ));

If you want to change to public access after upload : 如果您要在上传后更改为公共访问权限:

$s3_response = $s3->set_object_acl($bucket,
                                    $file_on_amazon_s3,
                                    AmazonS3::ACL_PUBLIC);

If you want to make a file public then In the permission array set uri to " http://acs.amazonaws.com/groups/global/AllUsers " and permission to "READ" 如果要公开文件,则在权限数组中将uri设置为“ http://acs.amazonaws.com/groups/global/AllUsers ”,并将权限设置为“ READ”

if (!class_exists('S3')) require 's3/S3.php'; 如果(!class_exists('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";
        }
        }

    }

}

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

相关问题 Amazon S3 PHP类,我可以直接将文件上传到存储桶中的文件夹吗 - Amazon S3 PHP Class, can I upload a file directly to a folder in a bucket 如何使用Amazon S3 SDK在存储桶中下载和执行php文件? - How can I download and execute a php file in a bucket using Amazon S3 SDK? 如何使用PHP预填充表格或将数据发送到第三方网站? - How can I use PHP to prepopulate a form on OR send data to a 3rd party website? 自动将文件从一个存储桶移动到另一个存储桶并在Amazon S3中公开 - Automatically move file from one bucket to another bucket and make public in Amazon S3 如何公开上传到Amazon s3的文件 - How to make a file public that is uploaded to Amazon s3 如何使用Codeigniter / PHP将文件上传到amazon S3? - How can I upload a file to amazon S3 with Codeigniter/PHP? 如何为 amazon S3 存储桶调整大小并上传图像? - How can I resize and upload an image for the amazon S3 bucket? 试图嵌入使用的第三方Javascript <?js= value ?> ,我怎么能阻止PHP解析“ - Trying to embed 3rd party Javascript that uses <?js= value ?>, how can i stop php from parsing the “<?” 如何将yii框架中的会话用于我的第三方应用程序 - How can i use session from yii framework into my 3rd party application 用于php的亚马逊s3 SDK无法获取Bucket对象列表 - Amazon s3 SDK for php can not get Bucket object list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM