本文整理汇总了PHP中AmazonS3::upload_part方法的典型用法代码示例。如果您正苦于以下问题:PHP AmazonS3::upload_part方法的具体用法?PHP AmazonS3::upload_part怎么用?PHP AmazonS3::upload_part使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AmazonS3
的用法示例。
在下文中一共展示了AmazonS3::upload_part方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
public static function send($settings = array(), $files = array(), $clear_uploads = false)
{
global $pb_backupbuddy_destination_errors;
if (!is_array($files)) {
$files = array($files);
}
if ($clear_uploads === false) {
// Uncomment the following line to override and always clear.
//$clear_uploads = true;
}
$itxapi_username = $settings['itxapi_username'];
$itxapi_password = $settings['itxapi_password'];
$db_archive_limit = $settings['db_archive_limit'];
$full_archive_limit = $settings['full_archive_limit'];
$max_chunk_size = $settings['max_chunk_size'];
$remote_path = self::get_remote_path($settings['directory']);
// Has leading and trailng slashes.
if ($settings['ssl'] == '0') {
$disable_ssl = true;
} else {
$disable_ssl = false;
}
$multipart_id = $settings['_multipart_id'];
$multipart_counts = $settings['_multipart_counts'];
pb_backupbuddy::status('details', 'Stash remote path set to `' . $remote_path . '`.');
require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
require_once dirname(__FILE__) . '/lib/aws-sdk/sdk.class.php';
// Stash API talk.
$stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
$manage_data = pb_backupbuddy_destination_stash::get_manage_data($settings);
// Wipe all current uploads.
if ($clear_uploads === true) {
pb_backupbuddy::status('details', 'Clearing any current uploads via Stash call to `abort-all`.');
$abort_url = $stash->get_upload_url(null, 'abort-all');
$request = new RequestCore($abort_url);
//pb_backupbuddy::status('details', print_r( $request , true ) );
$response = $request->send_request(true);
}
// Process multipart transfer that we already initiated in a previous PHP load.
if ($multipart_id != '') {
// Multipart upload initiated and needs parts sent.
// Create S3 instance.
pb_backupbuddy::status('details', 'Creating Stash S3 instance.');
$s3 = new AmazonS3($settings['_multipart_upload_data']['credentials']);
// the key, secret, token
if ($disable_ssl === true) {
@$s3->disable_ssl(true);
}
pb_backupbuddy::status('details', 'Stash S3 instance created.');
$this_part_number = $settings['_multipart_partnumber'] + 1;
pb_backupbuddy::status('details', 'Stash beginning upload of part `' . $this_part_number . '` of `' . count($settings['_multipart_counts']) . '` parts of file `' . $settings['_multipart_file'] . '` with multipart ID `' . $settings['_multipart_id'] . '`.');
$response = $s3->upload_part($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id'], array('expect' => '100-continue', 'fileUpload' => $settings['_multipart_file'], 'partNumber' => $this_part_number, 'seekTo' => (int) $settings['_multipart_counts'][$settings['_multipart_partnumber']]['seekTo'], 'length' => (int) $settings['_multipart_counts'][$settings['_multipart_partnumber']]['length']));
if (!$response->isOK()) {
$this_error = 'Stash unable to upload file part for multipart upload `' . $settings['_multipart_id'] . '`. Details: `' . print_r($response, true) . '`.';
$pb_backupbuddy_destination_errors[] = $this_error;
pb_backupbuddy::status('error', $this_error);
return false;
}
// Update stats.
foreach (pb_backupbuddy::$options['remote_sends'] as $identifier => $remote_send) {
if (isset($remote_send['_multipart_id']) && $remote_send['_multipart_id'] == $multipart_id) {
// this item.
pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = 'Sent part ' . $this_part_number . ' of ' . count($settings['_multipart_counts']) . '.';
if ($this_part_number == count($settings['_multipart_counts'])) {
pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] .= '<br>Success.';
pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time();
}
pb_backupbuddy::save();
break;
}
}
// Made it here so success sending part. Increment for next part to send.
$settings['_multipart_partnumber']++;
if (!isset($settings['_multipart_counts'][$settings['_multipart_partnumber']])) {
// No more parts exist for this file. Tell S3 the multipart upload is complete and move on.
pb_backupbuddy::status('details', 'Stash getting parts with etags to notify S3 of completed multipart send.');
$etag_parts = $s3->list_parts($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id']);
pb_backupbuddy::status('details', 'Stash got parts list. Notifying S3 of multipart upload completion.');
$response = $s3->complete_multipart_upload($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id'], $etag_parts);
if (!$response->isOK()) {
$this_error = 'Stash unable to notify S3 of completion of all parts for multipart upload `' . $settings['_multipart_id'] . '`.';
$pb_backupbuddy_destination_errors[] = $this_error;
pb_backupbuddy::status('error', $this_error);
return false;
} else {
pb_backupbuddy::status('details', 'Stash notified S3 of multipart completion.');
}
// Notify Stash API that things were succesful.
$done_url = $stash->get_upload_url($settings['_multipart_file'], 'done', $remote_path . $settings['_multipart_backup_type_dir'] . basename($settings['_multipart_file']));
pb_backupbuddy::status('details', 'Notifying Stash of completed multipart upload with done url `' . $done_url . '`.');
$request = new RequestCore($done_url);
$response = $request->send_request(true);
if (!$response->isOK()) {
$this_error = 'Error #756834682. Could not finalize Stash upload. Response code: `' . $response->get_response_code() . '`; Response body: `' . $response->get_response_body() . '`; Response headers: `' . $response->get_response_header() . '`.';
$pb_backupbuddy_destination_errors[] = $this_error;
pb_backupbuddy::status('error', $this_error);
return false;
} else {
// Good server response.
// See if we got an optional json response.
//.........这里部分代码省略.........
示例2: send
public static function send($settings = array(), $files = array(), $send_id = '', $clear_uploads = false)
{
global $pb_backupbuddy_destination_errors;
if (!is_array($files)) {
$files = array($files);
}
if ($clear_uploads === false) {
// Uncomment the following line to override and always clear.
//$clear_uploads = true;
}
$itxapi_username = $settings['itxapi_username'];
$itxapi_password = $settings['itxapi_password'];
$db_archive_limit = $settings['db_archive_limit'];
$full_archive_limit = $settings['full_archive_limit'];
$files_archive_limit = $settings['files_archive_limit'];
$max_chunk_size = $settings['max_chunk_size'];
$remote_path = self::get_remote_path($settings['directory']);
// Has leading and trailng slashes.
if ($settings['ssl'] == '0') {
$disable_ssl = true;
} else {
$disable_ssl = false;
}
$multipart_id = $settings['_multipart_id'];
$multipart_counts = $settings['_multipart_counts'];
pb_backupbuddy::status('details', 'Stash remote path set to `' . $remote_path . '`.');
require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php';
// Stash API talk.
$stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
$manage_data = pb_backupbuddy_destination_stash::get_manage_data($settings);
if (!is_array($manage_data['credentials'])) {
pb_backupbuddy::status('error', 'Error #8484383b: Your authentication credentials for Stash failed. Verify your login and password to Stash. You may need to update the Stash destination settings. Perhaps you recently changed your password?');
return false;
}
// Wipe all current uploads.
if ($clear_uploads === true) {
pb_backupbuddy::status('details', 'Clearing any current uploads via Stash call to `abort-all`.');
$abort_url = $stash->get_upload_url(null, 'abort-all');
$request = new RequestCore($abort_url);
$response = $request->send_request(true);
}
// Process multipart transfer that we already initiated in a previous PHP load.
if ($multipart_id != '') {
// Multipart upload initiated and needs parts sent.
// Create S3 instance.
pb_backupbuddy::status('details', 'Creating Stash S3 instance.');
$s3 = new AmazonS3($settings['_multipart_upload_data']['credentials']);
// the key, secret, token
if ($disable_ssl === true) {
@$s3->disable_ssl(true);
}
pb_backupbuddy::status('details', 'Stash S3 instance created.');
$backup_type = str_replace('/', '', $settings['_multipart_backup_type_dir']);
// For use later by file limiting.
$this_part_number = $settings['_multipart_partnumber'] + 1;
pb_backupbuddy::status('details', 'Stash beginning upload of part `' . $this_part_number . '` of `' . count($settings['_multipart_counts']) . '` parts of file `' . $settings['_multipart_file'] . '` with multipart ID `' . $settings['_multipart_id'] . '`.');
$response = $s3->upload_part($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id'], array('expect' => '100-continue', 'fileUpload' => $settings['_multipart_file'], 'partNumber' => $this_part_number, 'seekTo' => (int) $settings['_multipart_counts'][$settings['_multipart_partnumber']]['seekTo'], 'length' => (int) $settings['_multipart_counts'][$settings['_multipart_partnumber']]['length']));
if (!$response->isOK()) {
$this_error = 'Stash unable to upload file part for multipart upload `' . $settings['_multipart_id'] . '`. Details: `' . print_r($response, true) . '`.';
$pb_backupbuddy_destination_errors[] = $this_error;
pb_backupbuddy::status('error', $this_error);
return false;
} else {
$uploaded_size = $response->header['_info']['size_upload'];
$uploaded_speed = $response->header['_info']['speed_upload'];
pb_backupbuddy::status('details', 'Uploaded size: ' . pb_backupbuddy::$format->file_size($uploaded_size) . ', Speed: ' . pb_backupbuddy::$format->file_size($uploaded_speed) . '/sec.');
}
// Load fileoptions to the send.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
$fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false);
if (true !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.2344848. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
$update_status = 'Sent part ' . $this_part_number . ' of ' . count($settings['_multipart_counts']) . '.';
// Made it here so success sending part. Increment for next part to send.
$settings['_multipart_partnumber']++;
if (!isset($settings['_multipart_counts'][$settings['_multipart_partnumber']])) {
// No more parts exist for this file. Tell S3 the multipart upload is complete and move on.
pb_backupbuddy::status('details', 'Stash getting parts with etags to notify S3 of completed multipart send.');
$etag_parts = $s3->list_parts($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id']);
pb_backupbuddy::status('details', 'Stash got parts list. Notifying S3 of multipart upload completion.');
$response = $s3->complete_multipart_upload($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id'], $etag_parts);
if (!$response->isOK()) {
$this_error = 'Stash unable to notify S3 of completion of all parts for multipart upload `' . $settings['_multipart_id'] . '`.';
$pb_backupbuddy_destination_errors[] = $this_error;
pb_backupbuddy::status('error', $this_error);
return false;
} else {
pb_backupbuddy::status('details', 'Stash notified S3 of multipart completion.');
}
$backup_type_dir = $settings['_multipart_backup_type_dir'];
// Notify Stash API that things were succesful.
$done_url = $stash->get_upload_url($settings['_multipart_file'], 'done', $remote_path . $backup_type_dir . basename($settings['_multipart_file']));
pb_backupbuddy::status('details', 'Notifying Stash of completed multipart upload with done url `' . $done_url . '`.');
$request = new RequestCore($done_url);
//.........这里部分代码省略.........
示例3: array
//.........这里部分代码省略.........
//storing the uploadID in DB
$backup_settings_values['s3_upload_id'][$historyID] = $upload_id;
$backup_settings_values['backup_file'] = $backup_file;
update_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
}
//get the parts of the big file
$parts = $s3->get_multipart_counts(iwp_mmb_get_file_size($backup_file), $upload_file_block_size);
//1 MB chunks
if ($retrace == 'set') {
$list_parts_response = $s3->list_parts($as3_bucket, $as3_file, $upload_id);
$partsArray = CFUtilities::convert_response_to_array($list_parts_response);
$nextPart = count($partsArray) + 1;
$this->statusLog($this->hisID, array('stage' => 's3MultiCall', 'status' => 'partiallyCompleted', 'statusMsg' => 'retracingValues', 'nextFunc' => 'amazons3_backup', 'task_result' => $task_result, 'responseParams' => $result_arr));
$retrace = 'unset';
}
//this is the main upload loop break it on when the timeLimit is reached
//chunk upload loop
$partsArraySize = count($parts);
$s3ChunkTimeTaken = 0;
$s3ChunkCount = 0;
$reloop = false;
$reloopCount = 0;
$status = '';
do {
$uploadLoopCount = 0;
if ($reloopCount == 0) {
$s3ChunkStartTime = $s3StartTime;
} else {
$s3ChunkStartTime = microtime(true);
}
foreach ($parts as $i => $part) {
$uploadLoopCount += 1;
if ($uploadLoopCount == $nextPart) {
$singleUploadResponse = $s3->upload_part($as3_bucket, $as3_file, $upload_id, array('fileUpload' => $backup_file, 'partNumber' => $i + 1, 'seekTo' => $part['seekTo'], 'length' => $part['length']));
$singleUploadResult = $singleUploadResponse->isOk();
echo "singleUploadResult - " . $singleUploadResult;
$singleUploadResponseArray = $cfu_obj->convert_response_to_array($singleUploadResponse);
/* $response = $s3->complete_multipart_upload($bucket, $filename, $upload_id, array(
array('PartNumber' => 1, 'ETag' => '"25e317773f308e446cc84c503a6d1f85"'),
array('PartNumber' => 2, 'ETag' => '"a6d1f85f58498973f308e446cc84c503"'),
array('PartNumber' => 3, 'ETag' => '"bed3c0a4a1407f584989b4009e9ce33f"'),
)); */
$nextPart = $uploadLoopCount;
$partsArray[$i + 1]['PartNumber'] = $i + 1;
$partsArray[$i + 1]['ETag'] = $singleUploadResponseArray['header']['etag'];
$chunkResult = array();
$chunkResult['partsArray'] = $partsArray;
$chunkResult['nextPart'] = $nextPart + 1;
$chunkResult['upload_id'] = $upload_id;
$nextPart = $nextPart + 1;
$backup_settings_values['s3_retrace_count'][$historyID] = 0;
update_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
$status = 'partiallyCompleted';
if ($nextPart == $partsArraySize + 1) {
$doComplete = true;
$status = 'completed';
}
$result_arr = array();
$result_arr['response_data'] = $chunkResult;
$result_arr['status'] = $status;
$result_arr['nextFunc'] = 'amazons3_backup';
$result_arr['s3Args'] = $tempArgs;
$result_arr['current_file_num'] = $current_file_num;
$task_result['task_results'][$historyID]['amazons3'][$current_file_num] = basename($backup_file);
$task_result['amazons3'][$current_file_num] = basename($backup_file);
$this->statusLog($this->hisID, array('stage' => 's3MultiCall', 'status' => 'completed', 'statusMsg' => 'nextCall', 'nextFunc' => 'amazons3_backup', 'task_result' => $task_result, 'responseParams' => $result_arr));