Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中使用AWS sdk进行s3和ec2的文件操作?_Php_Amazon Web Services_Amazon S3_Amazon Ec2_Aws Sdk - Fatal编程技术网

如何在PHP中使用AWS sdk进行s3和ec2的文件操作?

如何在PHP中使用AWS sdk进行s3和ec2的文件操作?,php,amazon-web-services,amazon-s3,amazon-ec2,aws-sdk,Php,Amazon Web Services,Amazon S3,Amazon Ec2,Aws Sdk,我遇到了这样一种情况:我还需要将文件写入S3和EC2 下面的代码可以完美地将文件写入S3,但不知道如何写入EC2 <?php if(file_exists('aws-autoloader.php')){ require 'aws-autoloader.php'; }else{ die( 'File does not exist'); } define('AWS_KEY','*****'); define

我遇到了这样一种情况:我还需要将文件写入S3和EC2

下面的代码可以完美地将文件写入S3,但不知道如何写入EC2

    <?php

    if(file_exists('aws-autoloader.php')){

        require 'aws-autoloader.php';
    }else{

        die( 'File does not exist');
    }

    define('AWS_KEY','*****');
    define('AWS_SECRET','********');

    use Aws\S3\S3Client;
    use Aws\Credentials\Credentials;

    $credentials = new Credentials(AWS_KEY, AWS_SECRET);

    $client = new S3Client([
        'version'     => 'latest',
        'region'      => 'ap-southeast-1',
        'credentials' => $credentials
    ]);

    $client->registerStreamWrapper();

    file_put_contents('s3://mybucket/abc/a.txt', 'test');

    @chmod('/var/app/current', 0755);

//Not able to write the content to EC2 instance
    @file_put_contents('/var/app/current/b.txt', 'test');
    @file_put_contents('file://var/app/current/b.txt', 'test');
    ?>

如果应用程序具有写入权限,则它在使用以下代码时不会出现任何问题

    file_put_contents('/var/app/current/b.txt', 'test');
or
    file_put_contents('file:///var/app/current/b.txt', 'test');

您的意思是必须将文件写入另一个实例吗?还是本地实例?如果是本地的,您的应用程序是否有权限写入
/var/app…
?非常抱歉,这是权限的问题