AWS SDK for PHP在亚马逊S3上传文件

时间:2016-04-28 09:37:14

标签: php amazon-web-services amazon-s3 aws-sdk

我遇到类似问题here

以下是我在sample.php中的代码

  ini_set('display_errors', 1); 
  error_reporting(E_ALL);
  require_once(__DIR__ . '/../vendor/autoload.php'); //aws library
  require_once(__DIR__ . '/Minesh/S3.class.php');

  $config['AWS_S3_BUCKET_USER_ASSETS'] = 'My_AWS_S3_BUCKET_USER_ASSETS';
  $config['AWS_DEFAULT_REGION'] = 'us-east-1';
  $config['AWS_S3_API_VERSION'] = '2006-03-01';     

  $config['AWS_ACCESS_KEY_ID'] = 'My_AWS_ACCESS_KEY_ID';
  $config['AWS_SECRET_ACCESS_KEY'] = 'My_AWS_SECRET_ACCESS_KEY'; 

  $config['DATABASE_USERNAME'] = 'My_DATABASE_USERNAME';
  $config['DATABASE_PASSWORD'] = 'My_DATABASE_PASSWORD';
  $config['DATABASE_NAME'] = 'My_DATABASE_NAME';
  $config['DATABASE_HOSTNAME'] = 'My_DATABASE_HOSTNAME';

  \Minesh\S3::setup($config);

以下是我在Minesh / S3.class.php中的代码

namespace Minesh;
use \Aws\S3\S3Client;


class S3 {
    const INSERT = 'INSERT INTO s3_urls (normal_path, s3_url) VALUES("%s", "%s")';
    const UPDATE = 'UPDATE s3_urls SET s3_url = "%s" WHERE normal_path = "%s"';
    const DELETE = 'DELETE FROM s3_urls WHERE normal_path = "%s"';
    const SELECT = 'SELECT * FROM s3_urls WHERE normal_path = "%s"';

    protected static $_user_asset_bucket;
    protected static $_acl = 'public-read';
    protected static $_token_length = 24;
    protected static $_s3_host = 'https://s3.amazonaws.com';

    protected static $_db;
    protected static $_client;


    public static function setup($config) {
        self::$_user_asset_bucket = $config['AWS_S3_BUCKET_USER_ASSETS'];

        $factory_args = array(
             'region' => $config['AWS_DEFAULT_REGION'],
             'version' => $config['AWS_S3_API_VERSION'],
        );

        // Using IAM roles in prod and QA, so no credentials should be specified here unless in dev.
        if (!empty($config['AWS_ACCESS_KEY_ID']) && !empty($config['AWS_SECRET_ACCESS_KEY'])) {
            $factory_args['credentials'] = array(
                'key'    => $config['AWS_ACCESS_KEY_ID'],
                'secret' => $config['AWS_SECRET_ACCESS_KEY'],
            );
        }                                          
        // When i print print_r(S3Client::factory($factory_args)); i get proper Aws\S3\S3Client Object in it but site goes blank when i assign to self::$_client 
        self::$_client = S3Client::factory($factory_args); 

    }
}  

我想知道,没有错误/没有异常,页面变成空白

  

PS:我今天遇到了这个问题,这段代码运行正常   在使用相同的服务器配置之前:)。

0 个答案:

没有答案