当前位置: 首页>>代码示例>>PHP>>正文


PHP AmazonS3类代码示例

本文整理汇总了PHP中AmazonS3的典型用法代码示例。如果您正苦于以下问题:PHP AmazonS3类的具体用法?PHP AmazonS3怎么用?PHP AmazonS3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AmazonS3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($options['app'], $options['env'], true);
     if (!sfConfig::get('app_sf_amazon_plugin_access_key', false)) {
         throw new sfException(sprintf('You have not set an amazon access key'));
     }
     if (!sfConfig::get('app_sf_amazon_plugin_secret_key', false)) {
         throw new sfException(sprintf('You have not set an amazon secret key'));
     }
     $s3 = new AmazonS3(sfConfig::get('app_sf_amazon_plugin_access_key'), sfConfig::get('app_sf_amazon_plugin_secret_key'));
     $this->s3_response = $s3->create_bucket($arguments['bucket'], $options['region'], $options['acl']);
     if ($this->s3_response->isOk()) {
         $this->log('Bucketed is being created...');
         /* Since AWS follows an "eventual consistency" model, sleep and poll
            until the bucket is available. */
         $exists = $s3->if_bucket_exists($arguments['bucket']);
         while (!$exists) {
             // Not yet? Sleep for 1 second, then check again
             sleep(1);
             $exists = $s3->if_bucket_exists($arguments['bucket']);
         }
         $this->logSection('Bucket+', sprintf('"%s" created successfully', $arguments['bucket']));
     } else {
         throw new sfException($this->s3_response->body->Message);
     }
 }
开发者ID:JoshuaEstes,项目名称:sfAmazonPlugin,代码行数:26,代码来源:s3CreatebucketTask.class.php

示例2: tearDown

 public function tearDown()
 {
     if ($this->instance) {
         $s3 = new AmazonS3(array('key' => $this->config['amazons3']['key'], 'secret' => $this->config['amazons3']['secret']));
         if ($s3->delete_all_objects($this->id)) {
             $s3->delete_bucket($this->id);
         }
     }
 }
开发者ID:ryanshoover,项目名称:core,代码行数:9,代码来源:amazons3.php

示例3: getFileUrl

 public function getFileUrl($remotePath)
 {
     $response = $this->_s3->update_object($this->_bucket, $remotePath, array('acl' => AmazonS3::ACL_PUBLIC));
     if (!$response->isOK()) {
         return false;
     } else {
         return $response->header['_info']['url'];
     }
 }
开发者ID:otis22,项目名称:reserve-copy-system,代码行数:9,代码来源:Amazon.php

示例4: deleteBucket

 public static function deleteBucket($app)
 {
     $user_storage_s3 = Doctrine::getTable('GcrUserStorageS3')->findOneByAppId($app->getShortName());
     if ($user_storage_s3) {
         $account = GcrUserStorageS3Table::getAccount($app);
         define('AWS_KEY', $account->getAccessKeyId());
         define('AWS_SECRET_KEY', $account->getSecretAccessKey());
         gcr::loadSdk('aws');
         $api = new AmazonS3();
         $api->delete_bucket($user_storage_s3->getBucketName(), true);
         $user_storage_s3->delete();
     }
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:13,代码来源:GcrUserStorageS3Table.class.php

示例5: delete_xid

function delete_xid($db, $xid)
{
    $data = $db->Raw("SELECT server, link FROM userdb_uploads WHERE xid='{$xid}'");
    $server = $data[0]['server'];
    $link = $data[0]['link'];
    if ($server == 's3') {
        $s3 = new AmazonS3();
        $s3->delete_object('fb-music', $link);
    } else {
        $split = split("/", $data[0]['link']);
        $link = "/var/www/music/users/" . $split[4] . "/" . $split[5] . "/" . $split[6];
        unlink($link);
    }
    $db->Raw("DELETE FROM userdb_uploads WHERE xid='{$xid}'");
}
开发者ID:sjlu,项目名称:fb-music-app,代码行数:15,代码来源:maintenance.php

示例6: moveObject

 /**
  * Move a file or folder to a specific location
  *
  * @param string $from The location to move from
  * @param string $to The location to move to
  * @param string $point
  * @return boolean
  */
 public function moveObject($from, $to, $point = 'append')
 {
     $this->xpdo->lexicon->load('source');
     $success = false;
     if (substr(strrev($from), 0, 1) == '/') {
         $this->xpdo->error->message = $this->xpdo->lexicon('s3_no_move_folder', array('from' => $from));
         return $success;
     }
     if (!$this->driver->if_object_exists($this->bucket, $from)) {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $from;
         return $success;
     }
     if ($to != '/') {
         if (!$this->driver->if_object_exists($this->bucket, $to)) {
             $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $to;
             return $success;
         }
         $toPath = rtrim($to, '/') . '/' . basename($from);
     } else {
         $toPath = basename($from);
     }
     $response = $this->driver->copy_object(array('bucket' => $this->bucket, 'filename' => $from), array('bucket' => $this->bucket, 'filename' => $toPath), array('acl' => AmazonS3::ACL_PUBLIC));
     $success = $response->isOK();
     if ($success) {
         $deleteResponse = $this->driver->delete_object($this->bucket, $from);
         $success = $deleteResponse->isOK();
     } else {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_folder_err_rename') . ': ' . $to . ' -> ' . $from;
     }
     return $success;
 }
开发者ID:nervlin4444,项目名称:modx-cms,代码行数:39,代码来源:mods3mediasource.class.php

示例7: s3

 /**
  * Gets s3 object
  *
  * @param  boolean   $debug return error message instead of script stop
  * @return \AmazonS3 s3 object
  */
 public function s3($debug = false)
 {
     // This is workaround to composer autoloader
     if (!class_exists('CFLoader')) {
         throw new ClassNotFoundException('Amazon: autoload failed');
     }
     if (empty($this->_s3)) {
         \CFCredentials::set(array('@default' => array('key' => $this->getOption('key'), 'secret' => $this->getOption('secret'))));
         $this->_s3 = new \AmazonS3();
         $this->_s3->use_ssl = false;
         $this->_buckets = fn_array_combine($this->_s3->get_bucket_list(), true);
     }
     $message = '';
     $bucket = $this->getOption('bucket');
     if (empty($this->_buckets[$bucket])) {
         $res = $this->_s3->create_bucket($bucket, $this->getOption('region'));
         if ($res->isOK()) {
             $res = $this->_s3->create_cors_config($bucket, array('cors_rule' => array(array('allowed_origin' => '*', 'allowed_method' => 'GET'))));
             if ($res->isOK()) {
                 $this->_buckets[$bucket] = true;
             } else {
                 $message = (string) $res->body->Message;
             }
         } else {
             $message = (string) $res->body->Message;
         }
     }
     if (!empty($message)) {
         if ($debug == true) {
             return $message;
         }
         throw new ExternalException('Amazon: ' . $message);
     }
     return $this->_s3;
 }
开发者ID:ambient-lounge,项目名称:site,代码行数:41,代码来源:Amazon.php

示例8: testRemove

 /**
  * @covers mychaelstyle\storage\providers\AmazonS3::remove
  * @covers mychaelstyle\storage\providers\AmazonS3::__mergePutOptions
  * @covers mychaelstyle\storage\providers\AmazonS3::__formatUri
  * @depends testPut
  */
 public function testRemove()
 {
     if ($this->markIncompleteIfNoNetwork()) {
         return true;
     }
     // remove
     $this->object->remove($this->uri);
 }
开发者ID:mychaelstyle,项目名称:php-utils,代码行数:14,代码来源:AmazonS3Test.php

示例9: execute

 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($options['app'], $options['env'], true);
     if (!sfConfig::get('app_sf_amazon_plugin_access_key', false)) {
         throw new sfException(sprintf('You have not set an amazon access key'));
     }
     if (!sfConfig::get('app_sf_amazon_plugin_secret_key', false)) {
         throw new sfException(sprintf('You have not set an amazon secret key'));
     }
     $s3 = new AmazonS3(sfConfig::get('app_sf_amazon_plugin_access_key'), sfConfig::get('app_sf_amazon_plugin_secret_key'));
     $response = $s3->delete_bucket($arguments['bucket'], $options['force']);
     if ($response->isOk()) {
         $this->logSection('Bucket-', sprintf('"%s" bucket has been deleted', $arguments['bucket']));
     } else {
         throw new sfException($this->body->Message);
     }
 }
开发者ID:JoshuaEstes,项目名称:sfAmazonPlugin,代码行数:17,代码来源:s3DeletebucketTask.class.php

示例10: execute

 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($options['app'], $options['env'], true);
     // initialize the database connection
     //    $databaseManager = new sfDatabaseManager($this->configuration);
     //    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     if (!sfConfig::get('app_sf_amazon_plugin_access_key', false)) {
         throw new sfException(sprintf('You have not set an amazon access key'));
     }
     if (!sfConfig::get('app_sf_amazon_plugin_secret_key', false)) {
         throw new sfException(sprintf('You have not set an amazon secret key'));
     }
     $s3 = new AmazonS3(sfConfig::get('app_sf_amazon_plugin_access_key'), sfConfig::get('app_sf_amazon_plugin_secret_key'));
     $response = $s3->list_buckets();
     if (!isset($response->body->Buckets->Bucket)) {
         throw new sfException($response->body->Message);
     }
     foreach ($response->body->Buckets->Bucket as $bucket) {
         $this->logSection(sprintf('%s', $bucket->Name), sprintf('created at "%s"', $bucket->Name, $bucket->CreationDate));
     }
 }
开发者ID:JoshuaEstes,项目名称:sfAmazonPlugin,代码行数:21,代码来源:s3ListbucketsTask.class.php

示例11: testSignature

 /**
  * testSetDate
  *
  * @return void
  * @author Rob Mcvey
  **/
 public function testSignature()
 {
     $this->AmazonS3->setDate('Sun, 22 Sep 2013 14:43:04 GMT');
     $stringToSign = "PUT" . "\n";
     $stringToSign .= "aUIOL+kLNYqj1ZPXnf8+yw==" . "\n";
     $stringToSign .= "image/png" . "\n";
     $stringToSign .= "Sun, 22 Sep 2013 14:43:04 GMT";
     $stringToSign .= "\n";
     $stringToSign .= "x-amz-acl:public-read" . "\n";
     $stringToSign .= "x-amz-meta-reviewedby:john.doe@yahoo.biz" . "\n";
     $stringToSign .= "/bucket/copify.png";
     $signature = $this->AmazonS3->signature($stringToSign);
     $this->assertEqual('gbcL98O77pVLUSdcSIz4RCAots4=', $signature);
     $this->AmazonS3 = new AmazonS3(array('bang', 'fizz', 'lulz'));
     $signature = $this->AmazonS3->signature($stringToSign);
     $this->assertEqual('dF2swNTRWEs9LiMxdxiVeWPwCR0=', $signature);
 }
开发者ID:eltonrodrigues,项目名称:cakephp-amazon-s3,代码行数:23,代码来源:AmazonS3Test.php

示例12: _testS3Bucket

 function _testS3Bucket()
 {
     $AmazonS3 = new AmazonS3("", "");
     $res = $AmazonS3->ListBuckets();
     $this->assertTrue(is_array($res->Bucket), "ListBuckets returned array");
     $res = $AmazonS3->CreateBucket("MySQLDumps");
     $this->assertTrue($res, "Bucket successfull created");
     $res = $AmazonS3->CreateObject("fonts/test.ttf", "offload-public", "/tmp/PhotoEditService.wsdl", "plain/text");
     $this->assertTrue($res, "Object successfull created");
     $res = $AmazonS3->DownloadObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull downloaded");
     $res = $AmazonS3->DeleteObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull removed");
 }
开发者ID:jasherai,项目名称:libwebta,代码行数:14,代码来源:tests.php

示例13: _testS3Bucket

 function _testS3Bucket()
 {
     $AmazonS3 = new AmazonS3("0EJNVE9QFYY3TD554T02", "VOtWnbI2PmsqKOqDNVVgfLVsEnGD/6miiYDY552S");
     $res = $AmazonS3->ListBuckets();
     $this->assertTrue(is_array($res->Bucket), "ListBuckets returned array");
     $res = $AmazonS3->CreateBucket("MySQLDumps");
     $this->assertTrue($res, "Bucket successfull created");
     $res = $AmazonS3->CreateObject("fonts/test.ttf", "offload-public", "/tmp/PhotoEditService.wsdl", "plain/text");
     $this->assertTrue($res, "Object successfull created");
     $res = $AmazonS3->DownloadObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull downloaded");
     $res = $AmazonS3->DeleteObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull removed");
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:14,代码来源:tests.php

示例14: error_reporting

 * v1. 22 June 2012
 *
 * what this script does?
 *
 * add caching  headers to an existing object
 *
 */
require_once "sdk-1.5.7/sdk.class.php";
error_reporting(-1);
$config = parse_ini_file("aws.ini");
$awsKey = $config["aws.key"];
$awsSecret = $config["aws.secret"];
$bucket = "test.indigloo";
$name = "garbage_bin_wallpaper.jpg";
$options = array("key" => $awsKey, "secret" => $awsSecret, "default_cache_config" => '', "certificate_authority" => true);
$s3 = new AmazonS3($options);
$exists = $s3->if_bucket_exists($bucket);
if (!$exists) {
    printf("S3 bucket %s does not exists \n", $bucket);
    exit;
}
$mime = NULL;
$response = $s3->get_object_metadata($bucket, $name);
//get content-type of existing object
if ($response) {
    $mime = $response["ContentType"];
}
if (empty($mime)) {
    printf("No mime found for object \n");
    exit;
}
开发者ID:rjha,项目名称:sc,代码行数:31,代码来源:s3-caching-headers.php

示例15: process_remote_copy

 function process_remote_copy($destination_type, $file, $settings)
 {
     pb_backupbuddy::status('details', 'Copying remote `' . $destination_type . '` file `' . $file . '` down to local.');
     pb_backupbuddy::set_greedy_script_limits();
     if (!class_exists('backupbuddy_core')) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     }
     // Determine destination filename.
     $destination_file = backupbuddy_core::getBackupDirectory() . basename($file);
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     pb_backupbuddy::status('details', 'Filename of resulting local copy: `' . $destination_file . '`.');
     if ($destination_type == 'stash2') {
         require_once ABSPATH . 'wp-admin/includes/file.php';
         pb_backupbuddy::status('details', 'About to begin downloading from URL.');
         $download = download_url($url);
         pb_backupbuddy::status('details', 'Download process complete.');
         if (is_wp_error($download)) {
             $error = 'Error #832989323: Unable to download file `' . $file . '` from URL: `' . $url . '`. Details: `' . $download->get_error_message() . '`.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         } else {
             if (false === copy($download, $destination_file)) {
                 $error = 'Error #3329383: Unable to copy file from `' . $download . '` to `' . $destination_file . '`.';
                 pb_backupbuddy::status('error', $error);
                 pb_backupbuddy::alert($error);
                 @unlink($download);
                 return false;
             } else {
                 pb_backupbuddy::status('details', 'File saved to `' . $destination_file . '`.');
                 @unlink($download);
                 return true;
             }
         }
     }
     // end stash2.
     if ($destination_type == 'stash') {
         $itxapi_username = $settings['itxapi_username'];
         $itxapi_password = $settings['itxapi_password'];
         // Load required files.
         pb_backupbuddy::status('details', 'Load Stash files.');
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/init.php';
         require_once dirname(dirname(__FILE__)) . '/destinations/_s3lib/aws-sdk/sdk.class.php';
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/lib/class.itx_helper.php';
         // Talk with the Stash API to get access to do things.
         pb_backupbuddy::status('details', 'Authenticating Stash for remote copy to local.');
         $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
         $manage_url = $stash->get_manage_url();
         $request = new RequestCore($manage_url);
         $response = $request->send_request(true);
         // Validate response.
         if (!$response->isOK()) {
             $error = 'Request for management credentials failed.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (!($manage_data = json_decode($response->body, true))) {
             $error = 'Did not get valid JSON response.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (isset($manage_data['error'])) {
             $error = 'Error: ' . implode(' - ', $manage_data['error']);
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         // Connect to S3.
         pb_backupbuddy::status('details', 'Instantiating S3 object.');
         $s3 = new AmazonS3($manage_data['credentials']);
         pb_backupbuddy::status('details', 'About to get Stash object `' . $file . '`...');
         try {
             $response = $s3->get_object($manage_data['bucket'], $manage_data['subkey'] . pb_backupbuddy_destination_stash::get_remote_path() . $file, array('fileDownload' => $destination_file));
         } catch (Exception $e) {
             pb_backupbuddy::status('error', 'Error #5443984: ' . $e->getMessage());
             error_log('err:' . $e->getMessage());
             return false;
         }
         if ($response->isOK()) {
             pb_backupbuddy::status('details', 'Stash copy to local success.');
             return true;
         } else {
             pb_backupbuddy::status('error', 'Error #894597845. Stash copy to local FAILURE. Details: `' . print_r($response, true) . '`.');
             return false;
         }
     } elseif ($destination_type == 'gdrive') {
         die('Not implemented here.');
         require_once pb_backupbuddy::plugin_path() . '/destinations/gdrive/init.php';
         $settings = array_merge(pb_backupbuddy_destination_gdrive::$default_settings, $settings);
         if (true === pb_backupbuddy_destination_gdrive::getFile($settings, $file, $destination_file)) {
             // success
             pb_backupbuddy::status('details', 'Google Drive copy to local success.');
             return true;
         } else {
             // fail
             pb_backupbuddy::status('details', 'Error #2332903. Google Drive copy to local FAILURE.');
//.........这里部分代码省略.........
开发者ID:elephantcode,项目名称:elephantcode,代码行数:101,代码来源:cron.php


注:本文中的AmazonS3类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。