Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.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';s的S3流包装器用于编写,但不用于读取_Php_Amazon Web Services_Amazon S3_Guzzle_Aws Php Sdk - Fatal编程技术网

用于PHP的AWS SDK';s的S3流包装器用于编写,但不用于读取

用于PHP的AWS SDK';s的S3流包装器用于编写,但不用于读取,php,amazon-web-services,amazon-s3,guzzle,aws-php-sdk,Php,Amazon Web Services,Amazon S3,Guzzle,Aws Php Sdk,为了方便起见,我决定使用AWS SDK的包装器,以便可以从S3存储桶中流式传输数据,但情况如下: 使用此代码写入我的bucket是有效的 $client = \Aws\Common\Aws::factory(array( 'key' => 'my key', 'secret' => 'my secret',)) ->get('S3'); $client->registerStreamWrapper(); $fh = fopen('s3://mybuck

为了方便起见,我决定使用AWS SDK的包装器,以便可以从S3存储桶中流式传输数据,但情况如下:

使用此代码写入我的bucket是有效的

$client = \Aws\Common\Aws::factory(array(
    'key' => 'my key',
    'secret' => 'my secret',))
->get('S3');

$client->registerStreamWrapper();

$fh = fopen('s3://mybucket/test.txt','w');
fwrite($fh, 'Test');
fclose($fh);
该文件在此操作后存在,因此一切正常,但之后我无法读取它,因为
fopen('s3://mybucket/test.txt','r')
失败并出现以下警告:

Warning: fopen(s3://mybucket/test.txt): failed to open stream: "Aws\S3\StreamWrapper::stream_open" call failed
。。。这个错误是:

Fatal error: Uncaught exception 'Guzzle\Common\Exception\RuntimeException' with message 'Error creating resource. [type] 2 [message] fopen(https://mybucket.s3.amazonaws.com/test.txt): failed to open stream: Invalid argument [file] phar://path/to/aws.phar/Guzzle/Stream/PhpStreamRequestFactory.php [line] 217' in phar://path/to/aws.phar/Guzzle/Stream/PhpStreamRequestFactory.php on line 271
因此,我可以捕获该异常,或者改用
getObject
,但我仍然无法读取文件流,这违背了目的。也许这不是一个大问题,但我不熟悉Guzzle和AWS SDK的内部工作原理

任何关于我做错了什么的帮助或指导都将不胜感激,我在谷歌上搜索了一段时间,但我找不到有用的信息来解决它,所以很可能这一切都是由于我的无能

提前谢谢


干杯。

请尝试在php.ini中启用openssl:

extension=php_openssl.dll

您是否打算从read fopen()中省略
'r'
参数?@MarcB忘记在问题中写入它(但它在代码中),感谢您的观察!