本文整理汇总了PHP中S3::getBucket方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::getBucket方法的具体用法?PHP S3::getBucket怎么用?PHP S3::getBucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3
的用法示例。
在下文中一共展示了S3::getBucket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listS3Images
private function listS3Images()
{
$s3 = new S3(WH_AWS_WIKIPHOTO_ACCESS_KEY, WH_AWS_WIKIPHOTO_SECRET_KEY);
$bucket_name = self::AWS_BUCKET;
$prefix = null;
$marker = null;
//$marker = 'paupau/257175/Make Chocolate-1.JPG';
$maxKeys = 1;
//$maxKeys = null;
$delimiter = null;
$returnCommonPrefixes = false;
$buckets = $s3->getBucket($bucket_name, $prefix, $marker, $maxKeys, $delimiter, $returnCommonPrefixes);
print "number of buckets: " . count($buckets) . "\n";
foreach ($buckets as $path => $details) {
// match string: username/(1234.zip or 1234/*.jpg)
if (!preg_match('@^([a-z][-._0-9a-z]{0,30})/([0-9]+)(\\.zip|/.+)$@i', $path, $m)) {
continue;
}
list(, $user, $id, $ending) = $m;
$id = intval($id);
if (!$id) {
continue;
}
/* if (in_array($user, self::$excludeUsers) // don't process anything in excluded people
|| preg_match('@^[0-9]+$@', $user)) // don't allow usernames that are all digits
{
continue;
}
*/
$prefix = $user . '/' . $id;
$files = array($ending);
list($err, $stageDir) = self::pullFiles($id, $s3, $prefix, $files);
}
}
示例2: ls
public static function ls($pattern = null)
{
global $globals;
S3::setAuth($globals['Amazon_access_key'], $globals['Amazon_secret_key']);
$list = S3::getBucket($globals['Amazon_S3_media_bucket'], $pattern);
return $list;
}
示例3: getBucketContents
/**
* Get S3 bucket contents (from cache if possible)
*
* @return array
*/
private function getBucketContents()
{
$cacheFile = $this->cacheDir . '/s3browser-' . $this->s3Bucket;
$contents = null;
// get from cache if valid
if ($this->cacheDuration && file_exists($cacheFile)) {
$cacheAge = time() - filectime($cacheFile);
if ($cacheAge < $this->cacheDuration) {
$contents = unserialize(file_get_contents($cacheFile));
}
}
// hit s3 if we didn't have anything cached
if (!$contents) {
$s3 = new S3($this->s3AccessKey, $this->s3SecretKey, $this->s3useSSL, $this->s3endPoint);
$contents = $s3->getBucket($this->s3Bucket);
// we weren't able to access the bucket
if (!is_array($contents)) {
return null;
}
// save if caching is enabled
if ($this->cacheDuration) {
file_put_contents($cacheFile, serialize($contents));
}
}
return $contents;
}
示例4: listS3Docs
private function listS3Docs()
{
$s3 = new S3(WH_AWS_WIKIPHOTO_ACCESS_KEY, WH_AWS_WIKIPHOTO_SECRET_KEY);
$bucket_name = self::AWS_BUCKET;
$prefix = null;
$marker = null;
$maxKeys = null;
$delimiter = null;
$returnCommonPrefixes = false;
$buckets = $s3->getBucket($bucket_name, $prefix, $marker, $maxKeys, $delimiter, $returnCommonPrefixes);
if (!self::$quiet) {
print "number of buckets: " . count($buckets) . "\n";
}
foreach ($buckets as $path => $details) {
// match string: doc_folder/doc_file.ending
if (!preg_match('@^(.*)/(.*)\\.(.*)$@i', $path, $m)) {
continue;
}
list(, $doc_folder, $doc_file, $ending) = $m;
//validate extension
if (!in_array($ending, self::$docExts)) {
continue;
}
$prefix = $doc_folder . '/' . $doc_file;
$files = array($ending);
list($err, $stageDir) = self::pullFiles($s3, $doc_folder, $doc_file, $ending);
}
//now process the display names
self::processDisplayNames($s3);
}
示例5: deleteSourceFolder
/**
* @inheritDoc BaseAssetSourceType::deleteSourceFolder()
*
* @param AssetFolderModel $parentFolder
* @param $folderName
*
* @return bool
*/
protected function deleteSourceFolder(AssetFolderModel $parentFolder, $folderName)
{
$this->_prepareForRequests();
$bucket = $this->getSettings()->bucket;
$objectsToDelete = $this->_s3->getBucket($bucket, $this->_getPathPrefix() . $parentFolder->path . $folderName);
foreach ($objectsToDelete as $uri) {
@$this->_s3->deleteObject($bucket, $uri['name']);
}
return true;
}
示例6: rotate
function rotate()
{
$maxAge = strtotime('1- Year');
$s3 = S3::getBucket($this->backupBucket);
// Organize Backups Chronologically
foreach ($s3 as $s3_filename => $data) {
$filename = substr($s3_filename, 0, strpos($s3_filename, '.'));
$backupgroup = substr($filename, 0, strlen($filename) - 25);
$timestamp = $data['time'];
$backups[$backupgroup][date('Y', $timestamp)][date('n', $timestamp)][date('j', $timestamp)][date('G', $timestamp)][] = $s3_filename;
}
// Get Expired Children of Each Backup Group
$expired = array();
$success = array();
// Separate Out File Types (Currently Unused)
foreach ($backups as $backupgroup => $data) {
// Year
foreach ($data as $year => $ydata) {
// Month
foreach ($ydata as $month => $mdata) {
$maxTime = mktime(23, 59, 59, $month, cal_days_in_month(CAL_GREGORIAN, $month, $year), $year);
if ($maxTime < $maxAge) {
$expired = array_merge($expired, $this->getChildren($mdata));
} else {
foreach ($mdata as $day => $ddata) {
$maxTime = mktime(23, 59, 59, $month, $day, $year);
if ($maxTime < $maxAge) {
$expired = array_merge($expired, $this->getChildren($ddata));
} else {
foreach ($ddata as $hour => $hdata) {
$maxTime = mktime($hour, 59, 59, $month, $day, $year);
if ($maxTime < $maxAge) {
$expired = array_merge($expired, $this->getChildren($hdata));
}
}
}
}
}
}
}
}
foreach ($expired as $object) {
$thisSuccess = $this->deleteObject($this->backupBucket, $object);
if ($thisSuccess) {
echo "Deleted ";
$success[] = $object;
} else {
echo "ERROR: Could Not Delete ";
}
echo $object . "\n";
}
echo "\n" . count($success) . " Backups Deleted";
}
示例7: isDir
/**
* Check - path is directory or not
*
* @param string $path Short path
*
* @return boolean
*/
public function isDir($path)
{
$result = false;
try {
$result = $this->client->getObjectInfo(\XLite\Core\Config::getInstance()->CDev->AmazonS3Images->bucket, $path);
if (is_array($result)) {
$result = $result['type'] == 'binary/octet-stream';
} else {
$result = (bool) $this->client->getBucket(\XLite\Core\Config::getInstance()->CDev->AmazonS3Images->bucket, $path);
}
} catch (\S3Exception $e) {
$result = false;
\XLite\Logger::getInstance()->registerException($e);
}
return $result;
}
示例8: S3copy
private function S3copy($file)
{
$fileok = true;
$s3 = new S3($this->AccessKey, $this->SecretKey);
$list = $s3->getBucket($this->AWSFolder);
foreach ($list as $existing) {
if ($existing['name'] === $file) {
$fileok = false;
}
}
if ($fileok) {
$put = $s3->putObject($s3->inputFile(ASSETS_PATH . DIRECTORY_SEPARATOR . $file), $this->AWSFolder, $file, S3::ACL_PRIVATE);
if ($put) {
echo $file . " transferred to S3<br>" . "\r\n";
} else {
echo $file . " unable to be transferred to S3<br>" . "\r\n";
}
} else {
echo $file . " already in S3<br>" . "\r\n";
}
}
示例9: yss_s3_edit
function yss_s3_edit($id = false)
{
global $wpdb, $yss_post_assoc;
$checked = array();
$s3file = yss_get($id);
$sql = 'SELECT ID, post_title
FROM ' . $wpdb->posts . '
WHERE post_status = "publish"
AND post_type IN ("page","post")
ORDER BY post_title';
$posts = $wpdb->get_results($sql);
if ($id) {
$sql = 'SELECT post_id
FROM ' . $yss_post_assoc . '
WHERE s3_id = ' . $id;
$results = $wpdb->get_results($sql);
foreach ($results as $result) {
$checked[] = $result->post_id;
}
}
echo ym_start_box($id ? 'Edit Video' : 'Add Video');
if (!$id) {
require_once YSS_CLASSES_DIR . 'S3.php';
$s3 = new S3();
$s3->setAuth(get_option('yss_user_key'), get_option('yss_secret_key'));
}
echo '
<table class="widefat form-table" style="width: 100%;" cellspacing="10">
<tr valign="top">
<td>
' . __('S3 Bucket/file', "ym") . '
</td>
<td>';
if (!$id) {
echo '
<select name="s3_file_select">
';
foreach ($s3->listBuckets() as $bucket) {
$thisbucket = $s3->getBucket($bucket);
foreach ($thisbucket as $file) {
echo '<option ';
if ($s3file->bucket . '/' . $s3file->resource_path == $bucket . '/' . $file['name']) {
echo 'selected="selected"';
}
echo '>' . $bucket . '/' . $file['name'] . '</option>';
}
}
echo '
</select>
';
} else {
echo $s3file->bucket . '/' . $s3file->resource_path;
echo '<input type="hidden" name="s3_file_select" value="' . $s3file->bucket . '/' . $s3file->resource_path . '" />';
}
echo '
</td>
</tr>
<tr valign="top">
<td>
' . __('Your Members Package Types access', "ym") . '
<div style="font-size: 10px; color: gray; margin-top: 10px;">Your videos can be protected by account type here. If none of the boxes are checked then it will fall back to the next section (post protection)</div>
</td><td>';
echo ' <div>';
if ($data = get_option('ym_account_types')) {
$types = $data->types;
$ac_checked = array();
if ($selected = @$s3file->account_types) {
$ac_checked = explode('||', $selected);
}
foreach ((array) $types as $type) {
$checked_string = '';
if (in_array($type, $ac_checked)) {
$checked_string = 'checked="checked"';
}
echo ' <div class="ym_setting_list_item">
<label>
<input type="checkbox" class="checkbox" name="account_types[]" value="' . $type . '" ' . $checked_string . ' /> ' . __($type) . '
</label>
</div>';
}
} else {
echo '<div>The system is unable to find any YM account types. Is there a problem with the install?</div>';
}
echo '</div>';
echo ' </td>
</tr>
<tr valign="top">
<td>
' . __('Restrict access by post/page?', "ym") . ' <input type="checkbox" name="memberonly" ' . (@$s3file->members ? "checked='checked'" : '') . ' /> (Check to activate)
<div style="font-size: 10px; color: gray; margin-top: 10px;">If the above account type check fails or you choose not to use it then you can optionally use this section. This will check access against a number of posts or pages and if at least one has access then the video will be shown.<br /><br />If the restrict access checkbox is unticked then YSS will assume that the video should remain unprotected (if you are not using the account type protection)</div>
</td>
<td>
<br /><select name="link_to_post_id[]" multiple size=10 style="height: 250px; width: 450px;">';
foreach ($posts as $row) {
$selected = in_array($row->ID, $checked) ? 'selected="selected"' : '';
echo '<option value="' . $row->ID . '" ' . $selected . ' >' . $row->post_title . '</option>';
}
echo ' </select>
</td>
</tr>';
//.........这里部分代码省略.........
示例10: str_replace
$objMossoAuth->authenticate();
// Let's get a connection to CloudFiles
$objMosso = new CF_Connection($objMossoAuth);
echo "Listing buckets from your Amazon S3\n";
$awsBucketList = $objS3->listBuckets();
echo str_replace('Array', 'Amazon S3 Buckets', print_r($awsBucketList, true)) . "\n";
foreach ($awsBucketList as $awsBucketName) {
if (in_array($awsBucketName, $awsExcludeBuckets)) {
echo "---> Bucket {$awsBucketName} will be excluded\n";
continue;
}
$mossoContainerName = $prefixToAddToContainers . $awsBucketName;
// TODO: check if Bucket is CDN enabled
// Get objects
echo "Listing objects in Bucket {$awsBucketName} \n";
$awsObjectList = $objS3->getBucket($awsBucketName);
// Create this bucket as a Container on MOSSO
echo "Creating Container {$mossoContainerName} in Cloud Files\n";
$objMossoContainer = $objMosso->create_container($mossoContainerName);
echo "Processing objects in Bucket {$awsBucketName} \n";
foreach ($awsObjectList as $awsObjectInfo) {
// Check if Object is in ignore list
if (in_array($awsObjectInfo["name"], $awsExcludeObjects[$awsBucketName])) {
echo "---> Object {$awsObjectInfo["name"]} will be excluded\n";
continue;
}
//$awsObjectInfo = $objS3->getObjectInfo($awsBucketName, $awsObjectName);
echo str_replace('Array', $awsObjectInfo["name"], print_r($awsObjectInfo, true));
// TODO: Get Metadata and convert them to Mosso
// Check if it's a folder
if (strstr($awsObjectInfo["name"], '_$folder$')) {
示例11: color
echo ' ' . color('◎ 執行開始 ◎', 'P') . "\n";
echo str_repeat('-', 80) . "\n";
// // ========================================================================
// // ========================================================================
// // ========================================================================
echo ' ➜ ' . color('初始化 S3 工具', 'g');
include_once 'libs/s3.php';
S3::init($access, $secret);
echo ' - ' . color('初始化成功!', 'C') . "\n";
echo str_repeat('-', 80) . "\n";
// // ========================================================================
// // ========================================================================
// // ========================================================================
echo ' ➜ ' . color('列出 S3 上所有檔案', 'g');
try {
$s3_files = array_filter(S3::getBucket($bucket), function ($s3_file) {
return preg_match('/^' . NAME . '\\//', $s3_file['name']);
});
echo color('(' . ($c = count($s3_files)) . ')', 'g') . ' - 100% - ' . color('取得檔案成功!', 'C') . "\n";
echo str_repeat('-', 80) . "\n";
} catch (Exception $e) {
echo ' - ' . color('取得檔案失敗!', 'R') . "\n";
exit;
}
// // ========================================================================
// // ========================================================================
// // ========================================================================
$i = 0;
$c = 5;
$local_files = array();
echo ' ➜ ' . color('列出即將上傳所有檔案', 'g');
示例12: file_listing
function file_listing()
{
require_once "S3.php";
global $aws_access, $aws_secret;
global $s3_bucket, $s3_path;
$listing = array();
$s3 = new S3($aws_access, $aws_secret);
foreach ($s3->getBucket($s3_bucket, $s3_path) as $file) {
if (preg_match('@^.*/([ab])/([0-9]+)\\.jpg$@i', $file['name'], $match)) {
$listing[$match[2]][$match[1]] = array('size' => $file['size'], 'time' => $file['time']);
}
}
return $listing;
}
示例13: sync
static function sync($task)
{
aws_s3::log("Amazon S3 Re-sync task started..");
batch::start();
$items = ORM::factory("item")->find_all();
$task->set("total_count", count($items));
$task->set("completed", 0);
if (!module::get_var("aws_s3", "synced", false)) {
aws_s3::log("Emptying contents of bucket");
$task->status = "Emptying contents of bucket";
$task->save();
require_once MODPATH . "aws_s3/lib/s3.php";
$s3 = new S3(module::get_var("aws_s3", "access_key"), module::get_var("aws_s3", "secret_key"));
$bucket = module::get_var("aws_s3", "bucket_name");
$resource = aws_s3::get_resource_url("");
$stuff = array_reverse(S3::getBucket($bucket, $resource));
$i = 0;
foreach ($stuff as $uri => $item) {
$i++;
aws_s3::log("Removing " . $uri . " from S3");
S3::deleteObject($bucket, $uri);
$task->percent_complete = round(20 * ($i / count($stuff)));
$task->save();
}
}
$task->percent_complete = 20;
aws_s3::log("Commencing upload tasks");
$task->state = "Commencing upload...";
$task->save();
$completed = $task->get("completed", 0);
$items = ORM::factory("item")->find_all();
foreach ($items as $item) {
try {
if ($item->id > 1) {
aws_s3::upload_item($item, aws_s3::get_upload_flags());
}
} catch (Exception $err) {
}
$completed++;
$task->set("completed", $completed);
$task->percent_complete = round(80 * ($completed / $task->get("total_count"))) + 20;
$task->status = $completed . " of " . $task->get("total_count") . " uploaded.";
$task->save();
}
$task->percent_complete = 100;
$task->state = "success";
$task->done = true;
aws_s3::log("Sync task completed successfully");
$task->status = "Sync task completed successfully";
module::set_var("aws_s3", "synced", true);
site_status::clear("aws_s3_not_synced");
batch::stop();
$task->save();
}
示例14: foreach
<th>Actions</th>
</tr>
</thead>
<tfoot>
<tr class="thead">
<th scope="col" class="check-column"><input type="checkbox" class="check-all-entries" /></th>
<th>Backup File</th>
<th>Last Modified ↓</th>
<th>File Size</th>
<th>Actions</th>
</tr>
</tfoot>
<tbody>
<?php
// List s3 backups
$results = $s3->getBucket($aws_bucket);
if (empty($results)) {
echo '<tr><td colspan="5" style="text-align: center;"><i>You have not created any S3 backups yet.</i></td></tr>';
} else {
$file_count = 0;
foreach ((array) $results as $rekey => $reval) {
// check if file is backup
$pos = strpos($rekey, $aws_directory . 'backup-');
if ($pos !== FALSE) {
$file_count++;
?>
<tr class="entry-row alternate">
<th scope="row" class="check-column"><input type="checkbox" name="files[]" class="entries" value="<?php
echo $rekey;
?>
" /></th>
示例15: get_contents
public function get_contents()
{
$s3 = new S3('csub001050', 'studiomaiocchi', true, 'seewebstorage.it');
$contents = $s3->getBucket('studiomaiocchistaging');
return $contents;
}