Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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 Amazon SDK-s3 putObject始终返回403_Php_Amazon Web Services_Amazon S3 - Fatal编程技术网

PHP Amazon SDK-s3 putObject始终返回403

PHP Amazon SDK-s3 putObject始终返回403,php,amazon-web-services,amazon-s3,Php,Amazon Web Services,Amazon S3,我正在尝试集成PHP Amazon SDK-S3API。我正在提供正确的凭证。但我不确定putObject参数。 这是我尝试的代码: try { $s3Client->putObject(array( 'Bucket' => $bucket, 'Key' => $filename, 'Body' => file_get_contents(drupal_realpath($file_path)), 'AC

我正在尝试集成PHP Amazon SDK-S3API。我正在提供正确的凭证。但我不确定putObject参数。 这是我尝试的代码:

  try {
    $s3Client->putObject(array(
      'Bucket' => $bucket,
      'Key'    => $filename,
      'Body'   => file_get_contents(drupal_realpath($file_path)),
      'ACL'         => 'public-read',
    ));
  } catch (S3Exception $e) {echo '<pre>';print_r($e);
        echo "There was an error uploading the file.\n";
  }
  exit;

$e->getMessage()
说了什么?用户拥有这个bucket吗?此外,凭据是否来自IAM用户?如果是,他们的策略是否允许putObject操作?不要使用
file\u get\u contents()
,这样会不必要地将整个文件加载到内存中。Do
'Body'=>fopen(drupal\u realpath($file\u path)、'r')
'SourceFile'=>drupal\u realpath($file\u path)
Aws\S3\Exception\AccessDeniedException Object
(
[response:protected] => Guzzle\Http\Message\Response Object
    (
        [body:protected] => Guzzle\Http\EntityBody Object
            (
                [contentEncoding:protected] => 
                [rewindFunction:protected] => 
                [stream:protected] => Resource id #219
                [size:protected] => 
                [cache:protected] => Array
                    (
                        [wrapper_type] => PHP
                        [stream_type] => TEMP
                        [mode] => w+b
                        [unread_bytes] => 0
                        [seekable] => 1
                        [uri] => php://temp
                        [is_local] => 1
                        [is_readable] => 1
                        [is_writable] => 1
                    )

                [customData:protected] => Array
                    (
                    )

            )

        [reasonPhrase:protected] => Forbidden
        [statusCode:protected] => 403
        [info:protected] => Array
            (
                [url] => https://s3.amazonaws.com/my_test/ak1.jpg
                [content_type] => application/xml
                [http_code] => 403
                [header_size] => 273
                [request_size] => 320
                [filetime] => -1
              .........................................................................................................