我还遇到了需要向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');
?>发布于 2015-12-04 02:58:35
如果应用程序有写权限,它可以在下面的代码中正常工作。
file_put_contents('/var/app/current/b.txt', 'test');
or
file_put_contents('file:///var/app/current/b.txt', 'test');https://stackoverflow.com/questions/34049098
复制相似问题