AWS getobject +在保存时设置预设

时间:2015-11-03 20:16:13

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

我正在使用AWS EC2 Ubuntu machineAWS PHP SDK V2.8处理cakephp 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')
    ));

1 个答案:

答案 0 :(得分: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);