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


PHP S3::listBuckets方法代码示例

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


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

示例1: sprintf

 /**
  * Creates bucket
  *
  * @param string $container_id
  * @param string $error
  * @return boolean
  */
 function create_container(&$container_id, &$error)
 {
     if (!$this->_init($error)) {
         return false;
     }
     $this->_set_error_handler();
     $buckets = @$this->_s3->listBuckets();
     if ($buckets === false) {
         $error = sprintf('Unable to list buckets (%s).', $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     if (in_array($this->_config['bucket'], (array) $buckets)) {
         $error = sprintf('Bucket already exists: %s.', $this->_config['bucket']);
         $this->_restore_error_handler();
         return false;
     }
     if (empty($this->_config['bucket_acl'])) {
         $this->_config['bucket_acl'] = S3::ACL_PRIVATE;
     }
     if (!isset($this->_config['bucket_location'])) {
         $this->_config['bucket_location'] = S3::LOCATION_US;
     }
     if (!@$this->_s3->putBucket($this->_config['bucket'], $this->_config['bucket_acl'], $this->_config['bucket_location'])) {
         $error = sprintf('Unable to create bucket: %s (%s).', $this->_config['bucket'], $this->_get_last_error());
         $this->_restore_error_handler();
         return false;
     }
     $this->_restore_error_handler();
     return true;
 }
开发者ID:easinewe,项目名称:Avec2016,代码行数:38,代码来源:S3.php

示例2: 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;
 }
开发者ID:kant312,项目名称:sop,代码行数:23,代码来源:S3AssetSourceType.php

示例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;
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:27,代码来源:amazon.php

示例4: wp_db_backup_completed

 public static function wp_db_backup_completed(&$args)
 {
     $destination_s3 = get_option('wp_db_backup_destination_s3');
     if (isset($destination_s3) && $destination_s3 == 1 && get_option('wpdb_dest_amazon_s3_bucket') && get_option('wpdb_dest_amazon_s3_bucket_key') && get_option('wpdb_dest_amazon_s3_bucket_secret')) {
         try {
             if (!class_exists('S3')) {
                 require_once 'S3.php';
             }
             // AWS access info
             if (!defined('awsAccessKey')) {
                 define('awsAccessKey', get_option('wpdb_dest_amazon_s3_bucket_key'));
             }
             if (!defined('awsSecretKey')) {
                 define('awsSecretKey', get_option('wpdb_dest_amazon_s3_bucket_secret'));
             }
             // Check for CURL
             if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) {
                 error_log("ERROR: CURL extension not loaded");
             }
             $s3 = new S3(awsAccessKey, awsSecretKey);
             $bucketName = get_option('wpdb_dest_amazon_s3_bucket');
             $result = $s3->listBuckets();
             if (get_option('wpdb_dest_amazon_s3_bucket')) {
                 if (in_array(get_option('wpdb_dest_amazon_s3_bucket'), $result)) {
                     if ($s3->putObjectFile($args[1], $bucketName, baseName($args[1]), S3::ACL_PUBLIC_READ)) {
                         error_log("S3::{$args['0']} upload in bucket {$bucketName}");
                         $args[2] = $args[2] . '<br> Upload Database Backup on s3 bucket ' . $bucketName;
                     } else {
                         error_log("S3::Failed to upload {$args['0']}");
                         $args[2] = $args[2] . '<br>Failed to upload Database Backup on s3 bucket ' . $bucketName;
                     }
                 } else {
                     error_log("Invalid bucket name or AWS details");
                     $args[2] = $args[2] . '<br>Invalid bucket name or AWS details';
                 }
             }
         } catch (Exception $e) {
             // echo ($e->getMessage());
             error_log("Invalid AWS details");
         }
     }
 }
开发者ID:Jerram-Marketing,项目名称:Gummer-Co,代码行数:42,代码来源:S3_upload.php

示例5: buckets

 /**
  * Creates bucket
  *
  * @param string $error
  * @return boolean
  */
 function create_bucket(&$error)
 {
     if (!$this->_init($error)) {
         return false;
     }
     $buckets = @$this->_s3->listBuckets();
     if (!$buckets) {
         $error = 'Unable to list buckets (check your credentials).';
         return false;
     }
     if (in_array($this->_config['bucket'], (array) $buckets)) {
         $error = sprintf('Bucket already exists: %s.', $this->_config['bucket']);
         return false;
     }
     if (!@$this->_s3->putBucket($this->_config['bucket'], S3::ACL_PUBLIC_READ)) {
         $error = sprintf('Unable to create bucket: %s.', $this->_config['bucket']);
         return false;
     }
     return true;
 }
开发者ID:alx,项目名称:SBek-Arak,代码行数:26,代码来源:S3.php

示例6:

 function upload_to_amazon($source_filename, $dest_filename, $image_type = IMAGETYPE_JPEG, $compression = 75, $permissions = null)
 {
     // Create local instance of image
     $this->save($source_filename, $image_type, $compression, $permissions);
     // Begin s3 sequence
     $s3 = new S3('AMAZON_ACCESS_TOKEN', 'AMAZON_SECRET_TOKEN');
     // Name each bucket off the domain
     $bucket = 'screenbin';
     // Make sure the bucket is there
     if (!in_array($bucket, $s3->listBuckets())) {
         $s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
     }
     // Upload to s3
     if ($s3->putObjectFile($source_filename, $bucket, $dest_filename, S3::ACL_PUBLIC_READ)) {
         // Delete local version of the file
         return true;
     } else {
         return false;
     }
 }
开发者ID:rice-university,项目名称:screen-bin,代码行数:20,代码来源:SimpleImage.php

示例7: 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;
 }
开发者ID:webremote,项目名称:craft_boilerplate,代码行数:30,代码来源:S3AssetSourceType.php

示例8: amazon_upload

 public function amazon_upload()
 {
     $persistence = $this->getPersistence();
     $data = $persistence['Nitro']['CDNAmazon'];
     $this->amazon_set_progress('Initializing connection...', 0, 0, true);
     if (!class_exists('S3')) {
         require_once DIR_SYSTEM . 'nitro/lib/S3.php';
     }
     $s3 = new S3($data['AccessKeyID'], $data['SecretAccessKey']);
     $buckets = $s3->listBuckets();
     if (is_array($buckets) && in_array($data['Bucket'], $buckets)) {
         $this->loadConfig();
         $this->loadCore();
         // The connection is successful. We can now start to upload :)
         // clearAmazonPersistence();
         $this->amazon_set_progress('Scanning files...');
         $files = array();
         $site_root = dirname(DIR_SYSTEM) . '/';
         if (!empty($data['SyncCSS'])) {
             $files = array_merge($files, $this->list_files_with_ext($site_root, 'css'));
         }
         if (!empty($data['SyncJavaScript'])) {
             $files = array_merge($files, $this->list_files_with_ext($site_root, 'js'));
         }
         if (!empty($data['SyncImages'])) {
             $files = array_merge($files, $this->list_files_with_ext($site_root, array('png', 'jpg', 'jpeg', 'gif', 'tiff', 'bmp')));
         }
         $all_size = 0;
         $admin_folder_parts = array_filter(explode('/', DIR_APPLICATION));
         $admin_folder = array_pop($admin_folder_parts) . '/';
         $site_root = dirname(DIR_SYSTEM) . '/';
         clearstatcache(true);
         foreach ($files as $i => $file) {
             $destination = substr($file, strlen($site_root));
             // If in admin folder, omit
             if (stripos($destination, $admin_folder) === 0) {
                 unset($files[$i]);
                 continue;
             }
             if (file_exists($file) && is_file($file)) {
                 $all_size += filesize($file);
             } else {
                 unset($files[$i]);
             }
         }
         $this->amazon_set_progress('Starting upload...', 0, $all_size);
         $this->amazon_upload_files($s3, $data['Bucket'], $files);
         $this->amazon_set_progress('Task finished!', 'success');
         if ($this->session_closed) {
             session_start();
             $this->session_closed = false;
         }
     } else {
         throw new Exception('The specified bucket does not exist. Please create it.');
     }
 }
开发者ID:BulatSa,项目名称:Ctex,代码行数:56,代码来源:nitro.php

示例9: exit

// Check if our upload file exists
if (!file_exists($uploadFile) || !is_file($uploadFile)) {
    exit("\nERROR: No such file: {$uploadFile}\n\n");
}
// Check for CURL
if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) {
    exit("\nERROR: CURL extension not loaded\n\n");
}
// Pointless without your keys!
if (awsAccessKey == 'change-this' || awsSecretKey == 'change-this') {
    exit("\nERROR: AWS access information required\n\nPlease edit the following lines in this file:\n\n" . "define('awsAccessKey', 'change-me');\ndefine('awsSecretKey', 'change-me');\n\n");
}
// Instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
// List your buckets:
echo "S3::listBuckets(): " . print_r($s3->listBuckets(), 1) . "\n";
// Create a bucket with public read access
if ($s3->putBucket($bucketName, S3::ACL_PUBLIC_READ)) {
    echo "Created bucket {$bucketName}" . PHP_EOL;
    // Put our file (also with public read access)
    if ($s3->putObjectFile($uploadFile, $bucketName, baseName($uploadFile), S3::ACL_PUBLIC_READ)) {
        echo "S3::putObjectFile(): File copied to {$bucketName}/" . baseName($uploadFile) . PHP_EOL;
        // Get the contents of our bucket
        $contents = $s3->getBucket($bucketName);
        echo "S3::getBucket(): Files in bucket {$bucketName}: " . print_r($contents, 1);
        // Get object info
        $info = $s3->getObjectInfo($bucketName, baseName($uploadFile));
        echo "S3::getObjectInfo(): Info for {$bucketName}/" . baseName($uploadFile) . ': ' . print_r($info, 1);
        // You can also fetch the object into memory
        // var_dump("S3::getObject() to memory", $s3->getObject($bucketName, baseName($uploadFile)));
        // Or save it into a file (write stream)
开发者ID:chiunti,项目名称:amazon-s3-php-class,代码行数:31,代码来源:example.php

示例10: die

defined('ABSPATH') or die("Direct access to the script does not allowed");
?>


<?php 
$awsAccessKey = get_option('s3_secure_url_aws_access_key');
$awsSecretKey = get_option('s3_secure_url_aws_secret_key');
if (!$awsAccessKey || !$awsSecretKey) {
    die('Please enter your Amazon S3 credentials on the <a href="' . admin_url('options-general.php?page=' . $this->plugin_slug) . '">options page</a>');
} else {
    require dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/S3.php';
    $s3Files = array();
    // Store bucket names and bucket files in array
    $AwsS3Client = new S3($awsAccessKey, $awsSecretKey);
    // Get all buckets
    $buckets = @$AwsS3Client->listBuckets();
    if (is_array($buckets)) {
        foreach ($buckets as $bucket) {
            // Get all objects in bucket
            $bucketFiles = $AwsS3Client->getBucket($bucket);
            if (is_array($bucketFiles)) {
                foreach ($bucketFiles as $filename => $fileinfo) {
                    // Get detailed info about object
                    $info = $AwsS3Client->getObjectInfo($bucket, $filename);
                    if (is_array($info)) {
                        //If object is not a folder and have a size>0 then add it to $s3Files array
                        if ($info['size'] > 0 && $info['type'] != 'binary/octet-stream') {
                            $s3Files[$bucket][] = $filename;
                        }
                    }
                }
开发者ID:agiza,项目名称:s3-secure-url,代码行数:31,代码来源:tinymce-plugin-popup.php

示例11: list_buckets

 public function list_buckets()
 {
     $s3 = new S3('csub001050', 'studiomaiocchi', true, 'seewebstorage.it');
     $res = $s3->listBuckets();
     return $res;
 }
开发者ID:EnricoSottile,项目名称:ammonio-sandbox,代码行数:6,代码来源:S3Service.php

示例12: testConfig

 function testConfig()
 {
     // Test S3 connection info
     @($access_key = DevblocksPlatform::importGPC($_POST['access_key'], 'string', ''));
     @($secret_key = DevblocksPlatform::importGPC($_POST['secret_key'], 'string', ''));
     @($bucket = DevblocksPlatform::importGPC($_POST['bucket'], 'string', ''));
     try {
         $s3 = new S3($access_key, $secret_key);
         if (@(!$s3->listBuckets())) {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
开发者ID:jstanden,项目名称:devblocks,代码行数:16,代码来源:Plugin.php

示例13: 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>';
//.........这里部分代码省略.........
开发者ID:AdultStack,项目名称:ap-members,代码行数:101,代码来源:yss_resource_functions.includes.php

示例14: foreach


//.........这里部分代码省略.........
                         break;
                     case 'unix':
                         $fsFactory = new FilesystemFactory($permFactory);
                         break;
                     case 'windows':
                         $fsFactory = new WindowsFilesystemFactory();
                         break;
                 }
                 $manager = new FTPFilesystemManager($wrapper, $fsFactory);
                 $dlVoter = new DownloaderVoter();
                 $ulVoter = new UploaderVoter();
                 $ulVoter->addDefaultFTPUploaders($wrapper);
                 $crVoter = new CreatorVoter();
                 $crVoter->addDefaultFTPCreators($wrapper, $manager);
                 $deVoter = new DeleterVoter();
                 $deVoter->addDefaultFTPDeleters($wrapper, $manager);
                 $ftp = new FTP($manager, $dlVoter, $ulVoter, $crVoter, $deVoter);
                 if (!$ftp) {
                     $this->b['error'] = _("Error creating the FTP object");
                     backup_log($this->b['error']);
                     return;
                 }
                 if (!$ftp->directoryExists(new Directory($path))) {
                     backup_log(sprintf(_("Creating directory '%s'"), $path));
                     try {
                         $ftp->create(new Directory($path), array(FTP::RECURSIVE => true));
                     } catch (\Exception $e) {
                         $this->b['error'] = sprintf(_("Directory '%s' did not exist and we could not create it"), $path);
                         backup_log($this->b['error']);
                         backup_log($e->getMessage());
                         return;
                     }
                 }
                 try {
                     backup_log(_("Saving file to remote ftp"));
                     $ftp->upload(new File($path . '/' . $this->b['_file'] . '.tgz'), $this->b['_tmpfile']);
                 } catch (\Exception $e) {
                     $this->b['error'] = _("Unable to upload file to the remote server");
                     backup_log($this->b['error']);
                     backup_log($e->getMessage());
                     return;
                 }
                 //run maintenance on the directory
                 $this->maintenance($s['type'], $path, $ftp);
                 break;
             case 'awss3':
                 //subsitute variables if nesesary
                 $s['bucket'] = backup__($s['bucket']);
                 $s['awsaccesskey'] = backup__($s['awsaccesskey']);
                 $s['awssecret'] = backup__($s['awssecret']);
                 $awss3 = new \S3($s['awsaccesskey'], $s['awssecret']);
                 // Does this bucket already exist?
                 $buckets = $awss3->listBuckets();
                 if (!in_array($s['bucket'], $buckets)) {
                     // Create the bucket
                     $awss3->putBucket($s['bucket'], \S3::ACL_PUBLIC_READ);
                 }
                 //copy file
                 if ($awss3->putObjectFile($this->b['_tmpfile'], $s['bucket'], $this->b['name'] . "/" . $this->b['_file'] . '.tgz', \S3::ACL_PUBLIC_READ)) {
                     dbug('S3 successfully uploaded your backup file.');
                 } else {
                     dbug('S3 failed to accept your backup file');
                 }
                 //run maintenance on the directory
                 $this->maintenance($s['type'], $s, $awss3);
                 break;
             case 'ssh':
                 //subsitute variables if nesesary
                 $s['path'] = backup__($s['path']);
                 $s['user'] = backup__($s['user']);
                 $s['host'] = backup__($s['host']);
                 $destdir = $s['path'] . '/' . $this->b['_dirname'];
                 //ensure directory structure
                 $cmd = fpbx_which('ssh') . ' -o StrictHostKeyChecking=no -i ';
                 $cmd .= $s['key'] . " -l " . $s['user'] . ' ' . $s['host'] . ' -p ' . $s['port'];
                 $cmd .= " 'mkdir -p {$destdir}'";
                 exec($cmd, $output, $ret);
                 if ($ret !== 0) {
                     backup_log("SSH Error ({$ret}) - Received " . json_encode($output) . " from {$cmd}");
                 }
                 $output = null;
                 //put file
                 // Note that SCP (*unlike SSH*) needs IPv6 addresses in ['s. Consistancy is awesome.
                 if (filter_var($s['host'], \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
                     $scphost = "[" . $s['host'] . "]";
                 } else {
                     $scphost = $s['host'];
                 }
                 $cmd = fpbx_which('scp') . ' -o StrictHostKeyChecking=no -i ' . $s['key'] . ' -P ' . $s['port'];
                 $cmd .= " " . $this->b['_tmpfile'] . " " . $s['user'] . "@{$scphost}:{$destdir}";
                 exec($cmd, $output, $ret);
                 if ($ret !== 0) {
                     backup_log("SCP Error ({$ret}) - Received " . json_encode($output) . " from {$cmd}");
                 }
                 //run maintenance on the directory
                 $this->maintenance($s['type'], $s);
                 break;
         }
     }
 }
开发者ID:ringfreejohn,项目名称:pbxframework,代码行数:101,代码来源:class.backup.php

示例15: upload_remote_backup

 public function upload_remote_backup($filename)
 {
     // Init
     global $config;
     $file_path = SITE_PATH . '/data/backups/' . $filename;
     // Amazon S3
     if ($config['backup_type'] == 'amazon') {
         // Set variables
         $bucket_name = 'synala';
         // Init client
         include_once SITE_PATH . '/data/lib/S3.php';
         $s3_client = new S3($config['backup_amazon_access_key'], $config['backup_amazon_secret_key']);
         // Create subject, if needed
         $buckets = $s3_client->listBuckets();
         if (!in_array($bucket_name, $buckets)) {
             $s3_client->putBucket($bucket_name, S3::ACL_PRIVATE);
         }
         $s3_files_tmp = $s3_client->getBucket($bucket_name);
         $s3_files = array_keys($s3_files_tmp);
         // Upload backup file
         $s3_client->putObjectFile($file_path, $bucket_name, $filename);
         // Remote FTP
     } elseif ($config['backup_type'] == 'ftp') {
         if ($config['backup_ftp_type'] == 'ftps') {
             $ftp_client = ftp_ssl_connect($config['backup_ftp_host'], 22, 360);
         } else {
             $ftp_client = ftp_connect($config['backup_ftp_host'], $config['backup_ftp_port']);
         }
         ftp_login($ftp_client, $config['backup_ftp_username'], $config['backup_ftp_password']);
         // Set transfer mode
         //$is_passive = $config['remote_backup_ftp_mode'] == 'passive' ? true : false;
         //ftp_pasv($ftp_client, $is_passive);
         // Upload file
         //if ($config['remote_backup_ftp_dir'] != '') { $filename = $config['remote_backup_ftp_dir'] . '/' . $filename; }
         @ftp_put($ftp_client, $filename, SITE_PATH . "/data/backups/{$filename}", FTP_BINARY);
         ftp_close($ftp_client);
         // Tarsnap
     } elseif ($config['backup_type'] == 'tarsnap') {
         system($config['backup_tarsnap_location'] . " -cf {$config['backup_tarsnap_archive']} " . SITE_PATH);
     }
     // Delete local file, if needed
     //if ($config['remote_backup_retain_local'] != 1 && is_file($file_path)) {
     //	@unlink($file_path);
     //}
 }
开发者ID:nachatate,项目名称:synala,代码行数:45,代码来源:backupmanager.php


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