本文整理汇总了PHP中RequestCore::set_write_file方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestCore::set_write_file方法的具体用法?PHP RequestCore::set_write_file怎么用?PHP RequestCore::set_write_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestCore
的用法示例。
在下文中一共展示了RequestCore::set_write_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* upload()
*
* Processes uploaded backup file.
*
* @return array True on upload success; false otherwise.
*/
function upload()
{
if (isset($_POST['upload']) && $_POST['upload'] == 'local') {
if (pb_backupbuddy::$options['password'] != '#PASSWORD#') {
$path_parts = pathinfo($_FILES['file']['name']);
if (strtolower(substr($_FILES['file']['name'], 0, 6)) == 'backup' && strtolower($path_parts['extension']) == 'zip') {
if (move_uploaded_file($_FILES['file']['tmp_name'], basename($_FILES['file']['name']))) {
pb_backupbuddy::alert('File Uploaded. Your backup was successfully uploaded.');
return true;
} else {
pb_backupbuddy::alert('Sorry, there was a problem uploading your file.', true);
return false;
}
} else {
pb_backupbuddy::alert('Only properly named BackupBuddy zip archives with a zip extension may be uploaded.', true);
return false;
}
} else {
pb_backupbuddy::alert('Upload Access Denied. To prevent unauthorized file uploads an importbuddy password must be configured and properly entered to use this feature.');
return false;
}
}
// DOWNLOAD FILE FROM STASH TO LOCAL.
if (pb_backupbuddy::_POST('upload') == 'stash') {
pb_backupbuddy::set_greedy_script_limits(true);
/*
echo '<pre>';
print_r( $_POST );
echo '</pre>';
*/
$requestcore_file = dirname(dirname(dirname(__FILE__))) . '/lib/requestcore/requestcore.class.php';
require_once $requestcore_file;
$link = pb_backupbuddy::_POST('link');
$destination_file = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . basename(pb_backupbuddy::_POST('link'));
$destination_file = substr($destination_file, 0, stripos($destination_file, '.zip') + 4);
$_GET['file'] = basename($destination_file);
$request = new RequestCore($link);
$request->set_write_file($destination_file);
echo '<div id="pb_importbuddy_working" style="padding: 20px;">Downloading backup from Stash to `' . $destination_file . '`...<br><br><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."><br><br></div>';
flush();
$response = $request->send_request(false);
if ($response !== true) {
pb_backupbuddy::alert('Error #8548459598. Unable to download file from Stash. You may manually download it and upload to the server via FTP.');
} else {
// No error.
if (!file_exists($destination_file)) {
pb_backupbuddy::alert('Error #34845745878. Stash returned a success but the backup file was not found locally. Check this server\'s directory write permissions. You may manually download it and upload to the server via FTP.');
}
}
echo '<script type="text/javascript">jQuery("#pb_importbuddy_working").hide();</script>';
}
}
示例2: auth
//.........这里部分代码省略.........
$stats = fstat($options[self::OSS_FILE_UPLOAD]);
if ($stats && $stats[self::OSS_SIZE] >= 0) {
$length = $stats[self::OSS_SIZE] - (int) $options[self::OSS_SEEK_TO];
}
}
$request->set_read_stream($options[self::OSS_FILE_UPLOAD], $length);
if ($headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
$headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
}
} else {
$request->set_read_file($options[self::OSS_FILE_UPLOAD]);
$length = $request->read_stream_size;
if (isset($options[self::OSS_CONTENT_LENGTH])) {
$length = $options[self::OSS_CONTENT_LENGTH];
} elseif (isset($options[self::OSS_SEEK_TO]) && isset($length)) {
$length -= (int) $options[self::OSS_SEEK_TO];
}
$request->set_read_stream_size($length);
if (isset($headers[self::OSS_CONTENT_TYPE]) && $headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
$extension = explode('.', $options[self::OSS_FILE_UPLOAD]);
$ext = array_pop($extension);
$mime_type = MimeTypes::get_mimetype($ext);
$headers[self::OSS_CONTENT_TYPE] = $mime_type;
}
}
$options[self::OSS_CONTENT_MD5] = '';
}
if (isset($options[self::OSS_SEEK_TO])) {
$request->set_seek_position((int) $options[self::OSS_SEEK_TO]);
}
if (isset($options[self::OSS_FILE_DOWNLOAD])) {
if (is_resource($options[self::OSS_FILE_DOWNLOAD])) {
$request->set_write_stream($options[self::OSS_FILE_DOWNLOAD]);
} else {
$request->set_write_file($options[self::OSS_FILE_DOWNLOAD]);
}
}
if (isset($options[self::OSS_METHOD])) {
$request->set_method($options[self::OSS_METHOD]);
$string_to_sign .= $options[self::OSS_METHOD] . "\n";
}
if (isset($options[self::OSS_CONTENT])) {
$request->set_body($options[self::OSS_CONTENT]);
if ($headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
$headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
}
$headers[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]);
$headers[self::OSS_CONTENT_MD5] = $this->hex_to_base64(md5($options[self::OSS_CONTENT]));
}
uksort($headers, 'strnatcasecmp');
foreach ($headers as $header_key => $header_value) {
$header_value = str_replace(array("\r", "\n"), '', $header_value);
if ($header_value !== '') {
$request->add_header($header_key, $header_value);
}
if (strtolower($header_key) === 'content-md5' || strtolower($header_key) === 'content-type' || strtolower($header_key) === 'date' || isset($options['self::OSS_PREAUTH']) && (int) $options['self::OSS_PREAUTH'] > 0) {
$string_to_sign .= $header_value . "\n";
} elseif (substr(strtolower($header_key), 0, 6) === self::OSS_DEFAULT_PREFIX) {
$string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
}
}
$string_to_sign .= '/' . $options[self::OSS_BUCKET];
$string_to_sign .= $this->enable_domain_style ? $options[self::OSS_BUCKET] != '' ? $options[self::OSS_OBJECT] == '/' ? '/' : '' : '' : '';
$string_to_sign .= rawurldecode($signable_resource) . urldecode($signable_query_string);
$msg .= "STRING TO SIGN:----------------------------------------------\n" . $string_to_sign . "\n";
$signature = base64_encode(hash_hmac('sha1', $string_to_sign, $this->access_key, true));
$request->add_header('Authorization', 'OSS ' . $this->access_id . ':' . $signature);
if (isset($options[self::OSS_PREAUTH]) && (int) $options[self::OSS_PREAUTH] > 0) {
return $this->request_url . $conjunction . self::OSS_URL_ACCESS_KEY_ID . '=' . $this->access_id . '&' . self::OSS_URL_EXPIRES . '=' . $options[self::OSS_PREAUTH] . '&' . self::OSS_URL_SIGNATURE . '=' . rawurlencode($signature);
} elseif (isset($options[self::OSS_PREAUTH])) {
return $this->request_url;
}
if ($this->debug_mode) {
$request->debug_mode = $this->debug_mode;
}
$msg .= "REQUEST HEADERS:----------------------------------------------\n" . serialize($request->request_headers) . "\n";
$request->send_request();
$response_header = $request->get_response_header();
$response_header['x-oss-request-url'] = $this->request_url;
$response_header['x-oss-redirects'] = $this->redirects;
$response_header['x-oss-stringtosign'] = $string_to_sign;
$response_header['x-oss-requestheaders'] = $request->request_headers;
$msg .= "RESPONSE HEADERS:----------------------------------------------\n" . serialize($response_header) . "\n";
$data = new ResponseCore($response_header, $request->get_response_body(), $request->get_response_code());
if ((int) $request->get_response_code() === 400 || (int) $request->get_response_code() === 500 || (int) $request->get_response_code() === 503) {
if ($this->redirects <= $this->max_retries) {
//设置休眠
$delay = (int) (pow(4, $this->redirects) * 100000);
usleep($delay);
$this->redirects++;
$data = $this->auth($options);
}
}
$msg .= "RESPONSE DATA:----------------------------------------------\n" . serialize($data) . "\n";
$msg .= date('Y-m-d H:i:s') . ":---LOG END---------------------------------------------------------------------------\n";
//add log
$this->log($msg);
$this->redirects = 0;
return $data;
}
示例3: auth
//.........这里部分代码省略.........
$request->set_useragent($user_agent);
// Streaming uploads
if (isset($options[self::OSS_FILE_UPLOAD])) {
if (is_resource($options[self::OSS_FILE_UPLOAD])) {
$length = null;
if (isset($options[self::OSS_CONTENT_LENGTH])) {
$length = $options[self::OSS_CONTENT_LENGTH];
} elseif (isset($options[self::OSS_SEEK_TO])) {
$stats = fstat($options[self::OSS_FILE_UPLOAD]);
if ($stats && $stats[self::OSS_SIZE] >= 0) {
$length = $stats[self::OSS_SIZE] - (int) $options[self::OSS_SEEK_TO];
}
}
$request->set_read_stream($options[self::OSS_FILE_UPLOAD], $length);
if ($headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
$headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
}
} else {
$request->set_read_file($options[self::OSS_FILE_UPLOAD]);
$length = $request->read_stream_size;
if (isset($options[self::OSS_CONTENT_LENGTH])) {
$length = $options[self::OSS_CONTENT_LENGTH];
} elseif (isset($options[self::OSS_SEEK_TO]) && isset($length)) {
$length -= (int) $options[self::OSS_SEEK_TO];
}
$request->set_read_stream_size($length);
if (isset($headers[self::OSS_CONTENT_TYPE]) && $headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
$mime_type = self::get_mime_type($options[self::OSS_FILE_UPLOAD]);
$headers[self::OSS_CONTENT_TYPE] = $mime_type;
}
}
}
if (isset($options[self::OSS_SEEK_TO])) {
$request->set_seek_position((int) $options[self::OSS_SEEK_TO]);
}
if (isset($options[self::OSS_FILE_DOWNLOAD])) {
if (is_resource($options[self::OSS_FILE_DOWNLOAD])) {
$request->set_write_stream($options[self::OSS_FILE_DOWNLOAD]);
} else {
$request->set_write_file($options[self::OSS_FILE_DOWNLOAD]);
}
}
if (isset($options[self::OSS_METHOD])) {
$request->set_method($options[self::OSS_METHOD]);
$string_to_sign .= $options[self::OSS_METHOD] . "\n";
}
if (isset($options[self::OSS_CONTENT])) {
$request->set_body($options[self::OSS_CONTENT]);
if ($headers[self::OSS_CONTENT_TYPE] === 'application/x-www-form-urlencoded') {
$headers[self::OSS_CONTENT_TYPE] = 'application/octet-stream';
}
$headers[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]);
$headers[self::OSS_CONTENT_MD5] = base64_encode(md5($options[self::OSS_CONTENT], true));
}
uksort($headers, 'strnatcasecmp');
foreach ($headers as $header_key => $header_value) {
$header_value = str_replace(array("\r", "\n"), '', $header_value);
if ($header_value !== '') {
$request->add_header($header_key, $header_value);
}
if (strtolower($header_key) === 'content-md5' || strtolower($header_key) === 'content-type' || strtolower($header_key) === 'date' || isset($options['self::OSS_PREAUTH']) && (int) $options['self::OSS_PREAUTH'] > 0) {
$string_to_sign .= $header_value . "\n";
} elseif (substr(strtolower($header_key), 0, 6) === self::OSS_DEFAULT_PREFIX) {
$string_to_sign .= strtolower($header_key) . ':' . $header_value . "\n";
}
}
$string_to_sign .= '/' . $options[self::OSS_BUCKET];
$string_to_sign .= $this->enable_domain_style ? $options[self::OSS_BUCKET] != '' ? $options[self::OSS_OBJECT] == '/' ? '/' : '' : '' : '';
$string_to_sign .= rawurldecode($signable_resource) . urldecode($signable_query_string);
$signature = base64_encode(hash_hmac('sha1', $string_to_sign, $this->access_key, true));
$request->add_header('Authorization', 'OSS ' . $this->access_id . ':' . $signature);
if (isset($options[self::OSS_PREAUTH]) && (int) $options[self::OSS_PREAUTH] > 0) {
$signed_url = $this->request_url . $conjunction . self::OSS_URL_ACCESS_KEY_ID . '=' . rawurlencode($this->access_id) . '&' . self::OSS_URL_EXPIRES . '=' . $options[self::OSS_PREAUTH] . '&' . self::OSS_URL_SIGNATURE . '=' . rawurlencode($signature);
return $signed_url;
} elseif (isset($options[self::OSS_PREAUTH])) {
return $this->request_url;
}
if ($this->debug_mode) {
$request->debug_mode = $this->debug_mode;
}
$request->send_request();
$response_header = $request->get_response_header();
$response_header['oss-request-url'] = $this->request_url;
$response_header['oss-redirects'] = $this->redirects;
$response_header['oss-stringtosign'] = $string_to_sign;
$response_header['oss-requestheaders'] = $request->request_headers;
$data = new ResponseCore($response_header, $request->get_response_body(), $request->get_response_code());
//retry if OSS Internal Error
if ((int) $request->get_response_code() === 500) {
if ($this->redirects <= $this->max_retries) {
//设置休眠
$delay = (int) (pow(4, $this->redirects) * 100000);
usleep($delay);
$this->redirects++;
$data = $this->auth($options);
}
}
$this->redirects = 0;
return $data;
}