本文整理汇总了PHP中League\Flysystem\Util::getStreamSize方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::getStreamSize方法的具体用法?PHP Util::getStreamSize怎么用?PHP Util::getStreamSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Util
的用法示例。
在下文中一共展示了Util::getStreamSize方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeStream
/**
* @inheritdoc
*/
public function writeStream($path, $resource, Config $config)
{
$size = Util::getStreamSize($resource);
list(, $err) = $this->streamUpload($path, $resource, $size);
if ($err !== null) {
return false;
}
return compact('size', 'path');
}
示例2: upload
/**
* Upload an object.
*
* @param $path
* @param $body
* @param Config $config
*
* @return array
*/
protected function upload($path, $body, Config $config)
{
$key = $this->applyPathPrefix($path);
$options = $this->getOptionsFromConfig($config);
$acl = isset($options['ACL']) ? $options['ACL'] : 'private';
if (!isset($options['ContentType']) && is_string($body)) {
$options['ContentType'] = Util::guessMimeType($path, $body);
}
if (!isset($options['ContentLength'])) {
$options['ContentLength'] = is_string($body) ? Util::contentSize($body) : Util::getStreamSize($body);
}
$this->s3Client->upload($this->bucket, $key, $body, $acl, ['params' => $options]);
return $this->normalizeResponse($options, $key);
}
示例3: updateStream
/**
* @inheritdoc
*/
public function updateStream($path, $resource, Config $config)
{
$size = Util::getStreamSize($resource);
$resumeUploader = new ResumeUploader($this->getUploadToken(), $path, $resource, $size, null, 'application/octet-stream');
list(, $err) = $resumeUploader->upload();
if ($err !== null) {
return false;
}
return compact('size', 'path');
}
示例4: updateStream
/**
* Update a file using a stream
*
* @param string $path
* @param resource $resource
* @param mixed $config Config object or visibility setting
* @return array|bool
*/
public function updateStream($path, $resource, Config $config)
{
$size = Util::getStreamSize($resource);
list($ret, $err) = Qiniu_RS_Rput($this->getClient(), $this->bucket, $path, $resource, $size, null);
if ($err !== null) {
return false;
}
return compact('size', 'path');
}
示例5: writeStream
/**
* {@inheritdoc}
*/
public function writeStream($path, $resource, Config $config)
{
$options = $this->getOptions($path, ['Content' => $resource, 'ContentType' => Util::guessMimeType($path, $resource), 'ContentLength' => Util::getStreamSize($resource)], $config);
if ($this->client->putObject($options) === false) {
return false;
}
return true;
}
示例6: writeStream
/**
* {@inheritdoc}
*/
public function writeStream($path, $resource, Config $config)
{
$options = ['Body' => $resource];
$options['ContentLength'] = Util::getStreamSize($resource);
$options = $this->getOptions($path, $options, $config);
return $this->writeObject($options);
}
示例7: upload
/**
* Upload an object.
*
* @param $path
* @param $body
* @param Config $config
*
* @return array
*/
protected function upload($path, $body, Config $config)
{
$options = $this->getOptionsFromConfig($config);
$response = null;
try {
if (is_string($body)) {
$response = $this->client->putObjectFromString($this->bucket, $path, $body, $options);
} else {
if (is_resource($body)) {
if (isset($options['file'])) {
$file = $options['file'];
} else {
$metadata = stream_get_meta_data($body);
$file = $metadata['uri'];
}
if ($file !== null) {
$response = $this->client->putObjectFromFile($this->bucket, $path, $file, $options);
} else {
if (!isset($options[BosOptions::CONTENT_TYPE])) {
}
if (!isset($options[BosOptions::CONTENT_LENGTH])) {
$contentLength = Util::getStreamSize($body);
} else {
$contentLength = $options[BosOptions::CONTENT_LENGTH];
unset($options[BosOptions::CONTENT_LENGTH]);
}
if (!isset($options[BosOptions::CONTENT_MD5])) {
$contentMd5 = base64_encode(HashUtils::md5FromStream($body, 0, $contentLength));
} else {
$contentMd5 = $options[BosOptions::CONTENT_MD5];
unset($options[BosOptions::CONTENT_MD5]);
}
$response = $this->client->putObject($this->bucket, $path, $body, $contentLength, $contentMd5, $options);
if (is_resource($body)) {
fclose($body);
}
}
} else {
throw new \InvalidArgumentException("{$body} type should be string or resource");
}
}
} catch (BceBaseException $e) {
if (stcmp(gettype($e), "BceClientException") == 0) {
$this->logger->debug("BceClientException: " . $e->getMessage());
}
if (stcmp(gettype($e), "BceServerException") == 0) {
$this->logger->debug("BceServerException: " . $e->getMessage());
}
if (is_resource($body)) {
fclose($body);
}
return false;
} catch (\InvalidArgumentException $e) {
$this->logger->debug("InvalidArgumentException: " . $e->getMessage());
if (is_resource($body)) {
fclose($body);
}
return false;
} catch (\Exception $e) {
$this->logger->debug("Exception: " . $e->getMessage());
if (is_resource($body)) {
fclose($body);
}
return false;
}
return $this->normalizeResponse($response->metadata, $path);
}
示例8: uploadStream
/**
* Do the actual upload of a file resource.
*
* @param string $path
* @param resource $resource
* @param WriteMode $mode
*
* @return array|false file metadata
*/
protected function uploadStream($path, $resource, WriteMode $mode)
{
$location = $this->applyPathPrefix($path);
// If size is zero, consider it unknown.
$size = Util::getStreamSize($resource) ?: null;
if (!($result = $this->client->uploadFile($location, $mode, $resource, $size))) {
return false;
}
return $this->normalizeResponse($result, $path);
}
示例9: writeStream
/**
* Write using a stream
*
* @param string $path
* @param resource $resource
* @param mixed $config ['visibility'='private', 'mimetype'='', 'Metadata'=[]]
*
* @return array file metadata
*/
public function writeStream($path, $resource, $config = null)
{
$config = Util::ensureConfig($config);
$options = array('Body' => $resource);
$options['ContentLength'] = Util::getStreamSize($resource);
$options = $this->getOptions($path, $options, $config);
return $this->writeObject($options);
}
示例10: updateStream
/**
* @inheritdoc
*/
public function updateStream($path, $resource, Config $config)
{
$size = Util::getStreamSize($resource);
$result = $this->streamUpload($path, $resource, $size);
if ($result !== null) {
return false;
}
return compact('size', 'path');
}
示例11: build
/**
* Build the request
*
* @param array $options
* @return RequestBuilder
*/
public function build($options)
{
$this->endpoint = $options['endpoint'];
$this->headers['Date'] = gmdate('D, d M Y H:i:s \\G\\M\\T');
if (isset($this->body)) {
if (is_resource($this->body)) {
$this->headers['Content-Length'] = Util::getStreamSize($this->body);
} else {
$this->headers['Content-Length'] = strlen($this->body);
}
$this->headers['Content-Md5'] = base64_encode($this->getMD5($this->body));
if (isset($options['Content-Type'])) {
$this->headers['Content-Type'] = $options['Content-Type'];
} else {
$this->headers['Content-Type'] = $this->getMimeType($this->path, $this->body);
}
} else {
$this->headers['Content-Md5'] = '';
$this->headers['Content-Type'] = '';
}
$this->headers['Host'] = $options['host'];
ksort($this->oss_headers);
foreach ($this->oss_headers as $k => $v) {
$this->headers[$k] = $v;
}
if (!isset($this->bucket)) {
$this->path = '/';
} else {
$this->path = '/' . $this->bucket . '/' . $this->path;
}
ksort($this->params);
ksort($this->overrides);
$query = array_merge($this->params, $this->overrides);
$query_str = http_build_query($query);
if (!empty($query_str)) {
$this->query = '?' . $query_str;
$this->query = str_replace('acl=', 'acl', $this->query);
}
ksort($this->headers);
$sign = new Signature($this);
$this->headers['Authorization'] = 'OSS ' . $options['access_id'] . ':' . $sign->create($options['access_key']);
return $this;
}
示例12: writeStream
/**
* {@inheritdoc}
*/
public function writeStream($path, $resource, Config $config)
{
$bucket = $this->bucket;
$options = $this->getOptions($this->options, $config);
$multipartLimit = $this->mbToBytes($options['Multipart']);
$size = Util::getStreamSize($resource);
$contents = fread($resource, $size);
if ($size > $multipartLimit) {
printf(__FUNCTION__ . ": OVER LIMIT\n");
printf($e->getMessage() . "\n");
return;
} else {
try {
$this->client->putObject($bucket, $path, $contents, $options);
} catch (OssException $e) {
printf(__FUNCTION__ . ": FAILED\n");
printf($e->getMessage() . "\n");
return;
}
}
}
示例13: writeStreamWithoutKey
public function writeStreamWithoutKey($resource, Config $config)
{
$size = Util::getStreamSize($resource);
$token = $config->get('token');
return $this->streamUpload(null, $resource, $size, 'application/octet-stream', null, $token);
}