本文整理汇总了PHP中S3::setAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::setAuth方法的具体用法?PHP S3::setAuth怎么用?PHP S3::setAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3
的用法示例。
在下文中一共展示了S3::setAuth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_s3
static function get_s3()
{
if (!self::$_s3) {
require_once MODPATH . "aws_s3/lib/s3.php";
S3::setAuth(module::get_var("aws_s3", "access_key"), module::get_var("aws_s3", "secret_key"));
S3::$useSSL = module::get_var("aws_s3", "use_ssl", false);
}
return self::$_s3;
}
示例2: execute
public function execute()
{
$this->AWS_ACCESS_KEY = 'YOUR_AWS_ACCESS_KEY';
$this->AWS_SECRET_KEY = 'YOUR_AWS_SECRET_KEY';
$this->AWS_S3_BUCKET = 'YOUR_AWS_S3_BUCKET';
$this->AWS_S3_PUBLIC = true;
$this->AWS_S3_SSL = false;
$s3 = new S3();
$s3->setAuth($this->AWS_ACCESS_KEY, $this->AWS_SECRET_KEY);
$s3->useSSL = $this->AWS_S3_SSL;
// In my situation the images were in two different S3 buckets already. It will search these locations to try and find it.
// Your images are probably local already, so you may need to modify the code further down to work with local directories.
//$s3Buckets = array(...);
$dbw = wfGetDB(DB_MASTER);
$counter = 0;
$iIncrement = 10000;
for ($i = 0;; $i += $iIncrement) {
$res = $dbw->select(array('image', 'imagelinks', 'page'), array('image.img_name', 'image.img_path', 'page.page_title'), 'image.img_name = imagelinks.il_to and imagelinks.il_from = page.page_id and page.page_namespace = 0 limit ' . $i . ', ' . $iIncrement, array());
if (!$res) {
echo 'No for rows.\\n';
exit;
}
$logoPath = '';
foreach ($res as $row) {
echo "counter:{$counter}\n";
echo "i:{$i}\n";
++$counter;
if (!$row->img_name || !$row->img_path) {
continue;
}
echo 'img_name:' . $row->img_name . "\n";
echo 'img_path:' . $row->img_path . "\n";
echo 'page_title:' . $row->page_title . "\n";
$file = wfFindFile($row->img_name, array());
if ($file) {
$path = $file->getFullUrl();
$path = str_replace('http://s3.amazonaws.com/' . $this->AWS_S3_BUCKET . '/', '', $path);
echo "path:{$path}\n";
// If you have images that are already stored locally, you will need to modify this section. Instead of an S3::copyObject you
// may need to use the S3::putObject method to upload your local copy.
foreach ($s3Buckets as $s3Bucket) {
if ($s3->copyObject($s3Bucket, $row->img_path, $this->AWS_S3_BUCKET, $path, $this->AWS_S3_PUBLIC ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE)) {
echo 'SUCCESS:' . $row->img_name . "\n";
break;
} else {
echo 'ERROR1:' . $row->img_name . "\n";
}
}
} else {
echo 'ERROR2:' . $row->img_name . "\n";
}
echo "\n";
}
}
}
示例3: _prepareForRequests
/**
* Prepare the S3 connection for requests to this bucket.
*
* @param $settings
*/
private function _prepareForRequests($settings = null)
{
if (is_null($settings)) {
$settings = $this->getSettings();
}
if (is_null($this->_s3)) {
$this->_s3 = new \S3($settings->keyId, $settings->secret);
}
\S3::setAuth($settings->keyId, $settings->secret);
$this->_s3->setEndpoint(static::getEndpointByLocation($settings->location));
}
示例4: 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;
}
示例5: __construct
/**
* component constructor - set up local vars based on settings array in controller
*/
public function __construct(ComponentCollection $collection, $settings = array())
{
parent::__construct($collection, $settings);
// setup the instance vars
if (!empty($settings)) {
foreach ($settings as $var => $val) {
$this->{$var} = $val;
}
} else {
if ($config = Configure::read('CakeS3')) {
foreach ($config as $var => $val) {
$this->{$var} = $val;
}
}
}
if (empty($this->s3Key) || empty($this->s3Secret)) {
throw new Exception('S3 Keys not set up. Unable to connect');
}
S3::setAuth($this->s3Key, $this->s3Secret);
S3::setEndpoint($this->endpoint);
}
示例6: save_image
function save_image($temp_file)
{
//generate a random ID for this image
// $this->image_key = md5(uniqid(rand(), true));
//use an md5 of the file as a hash to prevent reuploads of the same file
$this->image_key = md5_file($temp_file);
//copy original
$original_file_name = IMAGES_DIR . "/original/" . $this->image_key . ".jpg";
$moved = rename($temp_file, $original_file_name);
if (!$moved) {
trigger_error("Failed to move image");
} else {
S3::setAuth(AWS_KEY, AWS_SECRET);
//save large
$this->save_sized_image($original_file_name, $this->image_key, IMAGE_LARGE_SIZE, "large");
//save medium
$this->save_sized_image($original_file_name, $this->image_key, IMAGE_MEDIUM_SIZE, "medium");
//save small
$this->save_sized_image($original_file_name, $this->image_key, IMAGE_SMALL_SIZE, "small");
//save thumbnail
$this->save_sized_image($original_file_name, $this->image_key, IMAGE_THUMBNAIL_SIZE, "thumbnail");
}
}
示例7: 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>';
//.........这里部分代码省略.........
示例8: switch
<?php
/*
* $Id: yss_s3.php 1754 2012-01-03 16:45:50Z BarryCarlyon $
* $Revision: 1754 $
* $Date: 2012-01-03 16:45:50 +0000 (Tue, 03 Jan 2012) $
*/
if ($task = @$_REQUEST['buckettask']) {
$s3 = new S3();
$s3->setAuth(get_option('yss_user_key'), get_option('yss_secret_key'));
switch ($task) {
case 'buckets':
echo '<select name="origin" id="origin">
<option value="">--Select--</option>
';
foreach ($s3->listBuckets() as $bucket) {
echo '<option value="' . $bucket . '">' . $bucket . '</option>';
}
echo '
</select>';
break;
default:
echo 'Nothing to do: ' . $task;
}
exit;
}
echo '<p>' . __('There is currently nothing to see here', 'yss') . '</p>';
示例9: buckets
public static function buckets($detailed = false)
{
global $globals;
S3::setAuth($globals['Amazon_access_key'], $globals['Amazon_secret_key']);
return S3::listBuckets($detailed);
}
示例10: validate_access_details
static function validate_access_details($access_key, $secret_key, $bucket_name)
{
require_once MODPATH . "aws_s3/lib/s3.php";
S3::setAuth($access_key, $secret_key);
S3::$useSSL = false;
$success_test = S3::putObjectString((string) time(), $bucket_name, ".s3_test");
if ($success_test) {
S3::deleteObject($bucket_name, ".s3_test");
}
return $success_test;
}
示例11: define
<?php
//include the S3 class
if (!class_exists('S3')) {
require_once 'S3.php';
}
//AWS access info
if (!defined('awsAccessKey')) {
define('awsAccessKey', 'AKIAICZOEWVDZ4COBAQQ');
}
if (!defined('awsSecretKey')) {
define('awsSecretKey', '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');
}
//instantiate the class
S3::setAuth(awsAccessKey, awsSecretKey);
示例12: yss_s3_distribution
function yss_s3_distribution($type, $id)
{
global $ym_formgen, $yss_cloudfront, $yss_db, $wpdb;
// file details
$s3file = yss_get($id);
if ($_POST) {
// here we go
$distro = $_POST['distro'];
list($can, $oai, $bucket, $file, $domain, $type) = explode('|', $distro);
$packet = array('type' => 'CanonicalUser', 'id' => $can, 'name' => 'CloudFront Origin Access Identity ' . $oai, 'permission' => 'READ');
$acp = array();
require_once YSS_CLASSES_DIR . 'S3.php';
$s3 = new S3();
$s3->setAuth(get_option('yss_user_key'), get_option('yss_secret_key'));
//get existing and merge
$acp = $s3->getAccessControlPolicy($bucket, $file);
$acp['acl'][] = $packet;
if ($s3->setAccessControlPolicy($bucket, $file, $acp)) {
$acp = $s3->getAccessControlPolicy($bucket, $file);
// store
$distribution = json_decode($s3file->distribution);
if ($type == 'stream') {
$distribution->streaming = $domain;
} else {
$distribution->download = $domain;
}
$distribution = json_encode($distribution);
$sql = 'UPDATE ' . $yss_db . ' SET
distribution = \'' . $distribution . '\'
WHERE id = ' . $id;
$wpdb->query($sql);
echo '<div id="message" class="updated"><p>Permissions updated</p></div>';
yss_s3_list();
return;
} else {
echo '<div id="message" class="error"><p>Permissions update failed</p></div>';
}
}
if ($type == 'stream') {
$data = $yss_cloudfront->get_streaming();
} else {
$data = $yss_cloudfront->get_distribution();
}
if (is_array($data)) {
$test = array_keys($data);
if ($test[0] != '0') {
$data = array($data);
}
}
if (is_array($data)) {
echo ym_box_top('Deploy');
echo '
<form action="" method="post">
<fieldset>
<p>You can select a distribution to expose the file, ' . $s3file->bucket . '/' . $s3file->resource_path . ' onto</p>
<table class="form-table">
';
$items = array('blank' => 'Select');
foreach ($data as $item) {
$bucket = $item['S3Origin']['DNSName']['value'];
list($bucket, $null) = explode('.', $bucket, 2);
$enabled = $item['Enabled']['value'];
if ($enabled == 'true' && $s3file->bucket == $bucket) {
// Distribution is enabled and is for this bucket matches
$status = $item['Status']['value'];
$domain = $item['DomainName']['value'];
$oai = $item['S3Origin']['OriginAccessIdentity']['value'];
list($null, $nulm, $oai) = explode('/', $oai);
// oai needs canonical
$canonical = $yss_cloudfront->get_oai_canonical($oai);
$value = $canonical . '|' . $oai . '|' . $bucket . '|' . $s3file->resource_path . '|' . $domain . '|' . $type;
//echo '<option value="' . $value . '">' . $domain . '</option>';
$items[$value] = $domain;
}
}
$ym_formgen->render_combo_from_array_row('Distribution', 'distro', $items, '', 'Which Distribution to expose this file on');
echo '
</table>
<p class="submit">
<input type="submit" value="Deploy!" />
</p>
</fieldset>
</form>
';
echo ym_box_bottom();
} else {
echo '<div id="message" class="error"><p>Failed to load Distributions or none available</p></div>';
}
}
示例13: deletestoryAction
public function deletestoryAction(Request $request)
{
/****** Admin session checking**********/
$response = $this->checkAdmin($request->getSession());
if ($response) {
return $response;
}
$story = new Story();
$em = $this->getDoctrine()->getManager();
$awsAccessKey = $this->container->get('mytrip_admin.helper.amazon')->getOption('awsAccessKey');
$awsSecretKey = $this->container->get('mytrip_admin.helper.amazon')->getOption('awsSecretKey');
$bucket = $this->container->get('mytrip_admin.helper.amazon')->getOption('bucket');
\S3::setAuth($awsAccessKey, $awsSecretKey);
/*****Single Story delete*******/
$id = $request->query->get('id');
if ($id != '') {
$storyimage = $em->createQuery("SELECT u FROM MytripAdminBundle:StoryImage u WHERE u.story ={$id}")->getArrayResult();
if (!empty($storyimage)) {
foreach ($storyimage as $simage) {
/*$file_path="img/story/".$simage['image'];
if($simage['image']!='' && file_exists($file_path)){
unlink($file_path);
}*/
$deleteobject = \S3::deleteObject($bucket, $simage['image']);
$em->createQuery("DELETE FROM MytripAdminBundle:StoryImage b WHERE b.storyImageId =" . $simage['storyImageId'])->execute();
}
}
$storybanner = $em->createQuery("SELECT u FROM MytripAdminBundle:Banner u WHERE u.bannerType='Story' AND u.typeId={$id}")->getArrayResult();
if (!empty($storybanner)) {
foreach ($storybanner as $bimage) {
/*$file_path="img/story/".$bimage['image'];
if($simage['image']!='' && file_exists($file_path)){
unlink($file_path);
}*/
$deleteobject = \S3::deleteObject($bucket, $bimage['image']);
$em->createQuery("DELETE FROM MytripAdminBundle:Banner b WHERE b.bannerId=" . $bimage['bannerId'])->execute();
}
}
$em->createQuery("DELETE FROM MytripAdminBundle:Story u WHERE u.storyId ={$id}")->execute();
$this->get('session')->getFlashBag()->add('error', '<div class="success msg">Story deleted successfully</div>');
return $this->redirect($this->generateUrl('mytrip_admin_story'));
}
/********Multiple Story delete**********/
if ($request->getMethod() == "POST") {
$storyid = $request->request->get('action');
$storyid = implode(",", $storyid);
$storyimage = $em->createQuery("SELECT u FROM MytripAdminBundle:StoryImage u WHERE u.story IN ({$storyid})")->getArrayResult();
if (!empty($storyimage)) {
foreach ($storyimage as $simage) {
/*$file_path="img/story/".$simage['image'];
if($simage['image']!='' && file_exists($file_path)){
unlink($file_path);
}*/
$deleteobject = \S3::deleteObject($bucket, $simage['image']);
$em->createQuery("DELETE FROM MytripAdminBundle:StoryImage b WHERE b.storyImageId =" . $simage['storyImageId'])->execute();
}
}
$storybanner = $em->createQuery("SELECT u FROM MytripAdminBundle:Banner u WHERE u.bannerType='Story' AND u.typeId IN ({$storyid})")->getArrayResult();
if (!empty($storybanner)) {
foreach ($storybanner as $bimage) {
/*$file_path="img/story/".$bimage['image'];
if($simage['image']!='' && file_exists($file_path)){
unlink($file_path);
}*/
$deleteobject = \S3::deleteObject($bucket, $bimage['image']);
$em->createQuery("DELETE FROM MytripAdminBundle:Banner b WHERE b.bannerId=" . $bimage['bannerId'])->execute();
}
}
$em->createQuery("DELETE FROM MytripAdminBundle:Story u WHERE u.storyId IN (" . $storyid . ")")->execute();
$this->get('session')->getFlashBag()->add('error', '<div class="success msg">Stories deleted successfully</div>');
return $this->redirect($this->generateUrl('mytrip_admin_story'));
}
if ($id == '' && $request->getMethod() != "POST") {
$this->get('session')->getFlashBag()->add('error', '<div class="error msg">Sorry, Story record not available</div>');
return $this->redirect($this->generateUrl('mytrip_admin_story'));
}
}
示例14: s3AuthenticatedURL
public static function s3AuthenticatedURL($uri)
{
S3::setAuth(S3_ACCESS_KEY, S3_SECRET_KEY);
//Save logging status
$save_logging = error_reporting();
// Turn off logging for S3
error_reporting(0);
$authUrl = S3::getAuthenticatedURL(S3_BUCKET, $uri, 10 * 24 * 60 * 60, false, true);
//10 days
// Restore logging status
error_reporting($save_logging);
//Debug results from Auth access
//error_log("s3Auth: $uri $authUrl");
return $authUrl;
}
示例15: imageExistsS3
/**
* Checks to see if image exists in the cloud
* @param string $imageName
* @return bool
*/
protected function imageExistsS3($imageName)
{
//Don't look for resizeds since we already looked in the db
if (strpos($imageName, 'w:')) {
error_log("S3: don't look for thumbnails {$imageName}");
return false;
}
S3::setAuth(S3_ACCESS_KEY, S3_SECRET_KEY);
try {
if (!($result = S3::getObject(S3_BUCKET, 'image/' . $imageName, false))) {
error_log("image not found on s3");
return false;
}
//Use to Debug S3 filecheck
//error_log("imageExistsS3: $imageName . ".print_r($result->code,true));
if ($result->code == 200) {
return true;
}
return false;
} catch (Exception $e) {
throw new Exception("imageExistsS3:getObject caught: {$e} imageName");
}
}