【问题标题】:AWS getobject + set premission while savingAWS getobject + 保存时设置权限
【发布时间】:2016-02-04 03:27:58
【问题描述】:

我正在使用 AWS EC2 Ubuntu machineAWS PHP SDK V2.8cakephp V2.3。我正在尝试将对象从 AWS S3 下载到我的 AWS 服务器。它工作正常只是一个问题是如何将文件的权限644 设置为777

这是我的代码。

        $saveAs = "/var/www/html/app/webroot/files/image/" . $result[$type][0]['id'] . "/" . $result[$type][0]['attachment'];
        $key = "files/image/" . $result[$type][0]['id'] . "/" . $result[$type][0]['attachment'];
        $result = $this->Amazon->S3->getObject(array(
            'Bucket' => 'mytest.sample',
            // 'Key' => 'avtar-auth_test_latest5.png',
            'Key' => $key,
            'version' => 'latest',
            'SaveAs' => $saveAs
        ));

我也试过

   $saveAs = "/var/www/html/app/webroot/files/image/" . $result[$type][0]['id'] . "/" . $result[$type][0]['attachment'];
    $key = "files/image/" . $result[$type][0]['id'] . "/" . $result[$type][0]['attachment'];
    $result = $this->Amazon->S3->getObject(array(
        'Bucket' => 'mytest.sample',
        // 'Key' => 'avtar-auth_test_latest5.png',
        'Key' => $key,
        'version' => 'latest',
        'SaveAs' => chmod($saveAs,'0777')
    ));

【问题讨论】:

    标签: php cakephp amazon-web-services amazon-ec2 file-permissions


    【解决方案1】:

    不要执行 chmod 函数并将其结果传递给 getObject 函数,而是在文件保存后使用单独的语句修改文件权限:

    $saveAs = "/var/www/html/app/webroot/files/image/" . $result[$type][0]['id'] . "/" . $result[$type][0]['attachment'];
    $key = "files/image/" . $result[$type][0]['id'] . "/" . $result[$type][0]['attachment'];
    $result = $this->Amazon->S3->getObject(array(
        'Bucket' => 'mytest.sample',
        // 'Key' => 'avtar-auth_test_latest5.png',
        'Key' => $key,
        'version' => 'latest',
        'SaveAs' => $saveAs
    ));
    
    chmod($saveAs,0777);
    

    【讨论】:

    • 它不工作。不知道为什么,但每当我使用我的文件权限设置为 411 而不是 777
    • 我犯了多么愚蠢的错误:)。无论如何,您应该将chmod($saveAs,'0777'); 更改为chmod($saveAs,0777);
    猜你喜欢
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    相关资源
    最近更新 更多