本文整理汇总了PHP中S3::getBucketLocation方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::getBucketLocation方法的具体用法?PHP S3::getBucketLocation怎么用?PHP S3::getBucketLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3
的用法示例。
在下文中一共展示了S3::getBucketLocation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBucketList
/**
* Get bucket list with credentials.
*
* @param $keyId
* @param $secret
*
* @throws Exception
* @return array
*/
public static function getBucketList($keyId, $secret)
{
$s3 = new \S3($keyId, $secret);
$buckets = @$s3->listBuckets();
if (empty($buckets)) {
throw new Exception(Craft::t("Credentials rejected by target host."));
}
$bucketList = array();
foreach ($buckets as $bucket) {
$location = $s3->getBucketLocation($bucket);
$bucketList[] = array('bucket' => $bucket, 'location' => $location, 'url_prefix' => 'http://' . static::getEndpointByLocation($location) . '/' . $bucket . '/');
}
return $bucketList;
}
示例2: __construct
/**
* Constructor
*
* @return void
*/
protected function __construct()
{
require_once LC_DIR_MODULES . 'CDev' . LC_DS . 'AmazonS3Images' . LC_DS . 'lib' . LC_DS . 'S3.php';
$config = \XLite\Core\Config::getInstance()->CDev->AmazonS3Images;
if ($config->access_key && $config->secret_key && function_exists('curl_init')) {
try {
$this->client = new \S3($config->access_key, $config->secret_key);
\S3::setExceptions(true);
if (!$this->client->getBucketLocation($config->bucket)) {
$this->client->putBucket($config->bucket);
}
$this->valid = true;
} catch (\S3Exception $e) {
\XLite\Logger::getInstance()->registerException($e);
}
}
}
示例3: getBuckets
/**
* Retrieves a list of buckets
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function getBuckets()
{
S3::setAuth($this->key, $this->secret);
$data = S3::listBuckets();
if (!$data) {
return false;
}
$buckets = array();
foreach ($data as $item) {
$bucket = new stdClass();
$bucket->title = $item;
// Get bucket location
$location = S3::getBucketLocation($item);
$bucket->locationTitle = $this->getLocationTitle($location);
$bucket->location = $location;
$buckets[] = $bucket;
}
return $buckets;
}
示例4: getBucketList
/**
* Get bucket list with credentials.
*
* @param $keyId
* @param $secret
*
* @throws Exception
* @return array
*/
public static function getBucketList($keyId, $secret)
{
$s3 = new \S3($keyId, $secret);
$s3->setExceptions(true);
try {
$buckets = $s3->listBuckets();
} catch (\Exception $exception) {
// Re-throw a proper Craft Exception
throw new Exception($exception->getMessage());
}
$bucketList = array();
foreach ($buckets as $bucket) {
try {
$location = $s3->getBucketLocation($bucket);
$bucketList[] = array('bucket' => $bucket, 'location' => $location, 'url_prefix' => 'http://' . static::getEndpointByLocation($location) . '/' . $bucket . '/');
} catch (\Exception $exception) {
continue;
}
}
return $bucketList;
}
示例5: dirname
function test_s3($accesskey, $secretkey, $bucket, $directory = '', $ssl)
{
if (empty($accesskey) || empty($secretkey) || empty($bucket)) {
return 'Missing one or more required fields.';
}
require_once dirname(__FILE__) . '/lib/s3/s3.php';
$s3 = new S3($accesskey, $secretkey);
if ($ssl != '1') {
S3::$useSSL = false;
}
if ($s3->getBucketLocation($bucket) === false) {
// Easy way to see if bucket already exists.
$s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
}
if (!empty($directory)) {
$directory = $directory . '/';
}
if ($s3->putObject('Upload test for BackupBuddy for Amazon S3', $bucket, $directory . 'backupbuddy.txt', S3::ACL_PRIVATE)) {
// Success... just delete temp test file later...
} else {
return 'Unable to upload. Verify your keys, bucket name, and account permissions.';
}
if (!S3::deleteObject($bucket, $directory . '/backupbuddy.txt')) {
return 'Partial success. Could not delete temp file.';
}
return true;
// Success!
}
示例6: S3MSAdminContent
function S3MSAdminContent()
{
if (isset($_POST['submit'])) {
$errors = array();
if (!isset($_POST['s3_bucket']) || trim($_POST['s3_bucket']) == '') {
$errors[] = "S3 Bucket Name Missing!";
}
$bucket = trim($_POST['s3_bucket']);
$ssl = isset($_POST['s3_ssl']) ? 1 : 0;
// Test connectivity
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'S3.php';
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 's3-access.php';
$s3_settings = new S3Access();
$s3 = new S3($s3_settings->get_access_key_id(), $s3_settings->get_secret_access_key());
$s3->setSSL((bool) $ssl);
$s3->setExceptions(true);
try {
$s3->getBucketLocation($bucket);
} catch (Exception $e) {
$errors[] = "Could not connect to bucket with the provided credentials!";
$errors[] = $e->getMessage();
}
if (!empty($errors)) {
$msg = implode('<br/>', $errors);
?>
<div class="error"><p><strong><?php
_e($msg, 'S3MS');
?>
</strong></p></div>
<?php
} else {
// No errors!
$settings = array('s3_bucket' => trim($_POST['s3_bucket']), 's3_bucket_path' => isset($_POST['s3_bucket_path']) ? ltrim(rtrim(trim($_POST['s3_bucket_path']), '/'), '/') : '', 's3_ssl' => isset($_POST['s3_ssl']) ? 1 : 0, 's3_delete_local' => isset($_POST['s3_delete_local']) ? 1 : 0, 's3_delete' => isset($_POST['s3_delete']) ? 1 : 0, 's3_expires' => trim($_POST['s3_expires']), 's3_cloudfront' => trim($_POST['s3_cloudfront']), 's3_rewrite_url' => trim($_POST['s3_rewrite_url']), 's3_protocol' => in_array(trim($_POST['s3_protocol']), array('http', 'https', 'relative')) ? trim($_POST['s3_protocol']) : 'relative', 'tiny_png_key' => trim($_POST['tiny_png_key']), 's3_transfer_method' => in_array(trim($_POST['s3_transfer_method']), array('s3class', 's3cmd', 'awscli', 'background')) ? trim($_POST['s3_transfer_method']) : 's3class', 'valid' => 1);
$settings = json_encode($settings);
$ret = update_option('S3MS_settings', $settings);
?>
<div class="updated"><p><strong><?php
_e('Settings Saved!', 'S3MS');
?>
</strong></p></div>
<?php
}
}
if (isset($_POST['move_files']) || isset($_POST['copy_files'])) {
$move = isset($_POST['move_files']) ? true : false;
$label = isset($_POST['move_files']) ? 'Moved' : 'Copied';
if (isset($_POST['selected']) && is_array($_POST['selected'])) {
$success_count = 0;
$error_count = 0;
foreach ($_POST['selected'] as $id) {
$ret = S3MS::updateAttachmentMetadata(array('S3MS_move' => $move), $id);
if ($ret) {
$success_count++;
} else {
$error_count++;
}
}
?>
<div class="updated"><p><strong><?php
_e(number_format($success_count) . ' File(s) ' . $label . '!', 'S3MS');
?>
</strong></p></div>
<?php
if ($error_count > 0) {
?>
<div class="error"><p><strong><?php
_e(number_format($error_count) . ' File(s) Could Not Be ' . $label . '!', 'S3MS');
?>
</strong></p></div>
<?php
}
}
}
// Get existing/POST options
$settings = json_decode(get_option('S3MS_settings'), true);
$s3_bucket = isset($_POST['s3_bucket']) ? trim($_POST['s3_bucket']) : null;
if (!$s3_bucket && is_array($settings) && isset($settings['s3_bucket'])) {
$s3_bucket = $settings['s3_bucket'];
}
$s3_bucket_path = isset($_POST['s3_bucket_path']) ? trim($_POST['s3_bucket_path']) : null;
if (!$s3_bucket_path && is_array($settings) && isset($settings['s3_bucket_path'])) {
$s3_bucket_path = $settings['s3_bucket_path'];
}
$s3_ssl = isset($_POST['s3_ssl']) ? (int) $_POST['s3_ssl'] : null;
if (!$s3_ssl && is_array($settings) && isset($settings['s3_ssl'])) {
$s3_ssl = (int) $settings['s3_ssl'];
}
$s3_delete_local = isset($_POST['s3_delete_local']) ? (int) $_POST['s3_delete_local'] : null;
if (!$s3_delete_local && is_array($settings) && isset($settings['s3_delete_local'])) {
$s3_delete_local = (int) $settings['s3_delete_local'];
}
$s3_delete = isset($_POST['s3_delete']) ? (int) $_POST['s3_delete'] : null;
if (!$s3_delete && is_array($settings) && isset($settings['s3_delete'])) {
$s3_delete = (int) $settings['s3_delete'];
}
$s3_expires = isset($_POST['s3_expires']) ? trim($_POST['s3_expires']) : null;
if (!$s3_expires && is_array($settings) && isset($settings['s3_expires'])) {
$s3_expires = $settings['s3_expires'];
}
$s3_cloudfront = isset($_POST['s3_cloudfront']) ? trim($_POST['s3_cloudfront']) : null;
//.........这里部分代码省略.........
示例7: periods
function test_s3($accesskey, $secretkey, $bucket, $directory = '', $ssl)
{
if (empty($accesskey) || empty($secretkey) || empty($bucket)) {
return __('Missing one or more required fields.', 'it-l10n-backupbuddy');
}
$bucket_requirements = __("Your bucket name must meet certain criteria. It must fulfill the following: \n\n Characters may be lowercase letters, numbers, periods (.), and dashes (-). \n Must start with a number or letter. \n Must be between 3 and 63 characters long. \n Must not be formatted as an IP address (e.g., 192.168.5.4). \n Should not contain underscores (_). \n Should be between 3 and 63 characters long. \n Should not end with a dash. \n Cannot contain two, adjacent periods. \n Cannot contain dashes next to periods.", 'it-l10n-backupbuddy');
if (preg_match("/^[a-z0-9][a-z0-9\\-\\.]*(?<!-)\$/i", $bucket) == 0) {
// Starts with a-z or 0-9; middle is a-z, 0-9, -, or .; cannot end in a dash.
return __('Your bucket contains a period next to a dash.', 'it-l10n-backupbuddy') . ' ' . $bucket_requirements;
}
if (strlen($bucket) < 3 || strlen($bucket) > 63) {
// Must be between 3 and 63 characters long
return __('Your bucket must be between 3 and 63 characters long.', 'it-l10n-backupbuddy') . ' ' . $bucket_requirements;
}
if (strstr($bucket, '.-') !== false || strstr($bucket, '-.') !== false || strstr($bucket, '..') !== false) {
// Bucket names cannot contain dashes next to periods (e.g., "my-.bucket.com" and "my.-bucket" are invalid)
return __('Your bucket contains a period next to a dash.', 'it-l10n-backupbuddy') . ' ' . $bucket_requirements;
}
require_once dirname(__FILE__) . '/lib/s3/s3.php';
$s3 = new S3($accesskey, $secretkey);
if ($ssl != '1') {
S3::$useSSL = false;
}
if ($s3->getBucketLocation($bucket) === false) {
// Easy way to see if bucket already exists.
$s3->putBucket($bucket, S3::ACL_PRIVATE);
}
if (!empty($directory)) {
$directory = $directory . '/';
}
if ($s3->putObject(__('Upload test for BackupBuddy for Amazon S3', 'it-l10n-backupbuddy'), $bucket, $directory . 'backupbuddy.txt', S3::ACL_PRIVATE)) {
// Success... just delete temp test file later...
} else {
return __('Unable to upload. Verify your keys, bucket name, and account permissions.', 'it-l10n-backupbuddy');
}
if (!S3::deleteObject($bucket, $directory . 'backupbuddy.txt')) {
return __('Partial success. Could not delete temp file.', 'it-l10n-backupbuddy');
}
return true;
// Success!
}