本文整理汇总了PHP中RequestCore::set_read_file方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestCore::set_read_file方法的具体用法?PHP RequestCore::set_read_file怎么用?PHP RequestCore::set_read_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestCore
的用法示例。
在下文中一共展示了RequestCore::set_read_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sign_url_for_put
function sign_url_for_put($obj)
{
global $bucket;
global $object;
$timeout = 3600;
//通过content上传
$options = NULL;
$response = $obj->presign_url($bucket, $object, $timeout, "PUT", $options);
SampleUtil::my_echo("签名的URL为:" . $response);
$content = 'abcdefg';
$request = new RequestCore($response);
$request->set_method('PUT');
$request->add_header('Content-Type', '');
$request->add_header('Content-Length', strlen($content));
$request->set_body($content);
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
if ($res->isOK()) {
SampleUtil::my_echo("签名上传字符串成功");
} else {
SampleUtil::my_echo("签名上传字符串失败");
}
//通过file上传
$file = __FILE__;
if (!file_exists($file)) {
throw new OSS_Exception($file . OSS_FILE_NOT_EXIST);
}
$options = array('Content-Type' => 'txt');
$response = $obj->presign_url($bucket, $object, $timeout, "PUT", $options);
SampleUtil::my_echo("签名的URL为:" . $response);
$request = new RequestCore($response);
$request->set_method('PUT');
$request->add_header('Content-Type', 'txt');
$request->set_read_file($file);
$request->set_read_stream_size(filesize($file));
$request->send_request();
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
if ($res->isOK()) {
SampleUtil::my_echo("签名上传文件成功");
} else {
SampleUtil::my_echo("签名上传字符串失败");
}
}
示例2: auth
//.........这里部分代码省略.........
if (isset($options[self::OSS_SUB_RESOURCE])) {
$signable_resource .= $conjunction . $options[self::OSS_SUB_RESOURCE];
$conjunction = '&';
}
if ($signable_query_string !== '') {
$signable_query_string = $conjunction . $signable_query_string;
$conjunction = '&';
}
if ($query_string !== '') {
$non_signable_resource .= $conjunction . $query_string;
$conjunction = '&';
}
$this->request_url = $scheme . $hostname . $signable_resource . $signable_query_string . $non_signable_resource;
$msg .= "--REQUEST URL:----------------------------------------------\n" . $this->request_url . "\n";
//创建请求
$request = new RequestCore($this->request_url);
// 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') {
$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]);
示例3: auth
//.........这里部分代码省略.........
$signable_resource .= $conjunction . $options[self::OSS_SUB_RESOURCE];
$conjunction = '&';
}
if ($signable_query_string !== '') {
$signable_query_string = $conjunction . $signable_query_string;
$conjunction = '&';
}
if ($query_string !== '') {
$non_signable_resource .= $conjunction . $query_string;
$conjunction = '&';
}
$this->request_url = $scheme . $hostname . $signable_resource . $signable_query_string . $non_signable_resource;
//创建请求
$request = new RequestCore($this->request_url);
$user_agent = OSS_NAME . "/" . OSS_VERSION . " (" . php_uname('s') . "/" . php_uname('r') . "/" . php_uname('m') . ";" . PHP_VERSION . ")";
$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';
}