本文整理汇总了PHP中League\Flysystem\FilesystemInterface::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::getSize方法的具体用法?PHP FilesystemInterface::getSize怎么用?PHP FilesystemInterface::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create the response.
*
* @param \League\Flysystem\FilesystemInterface $cache The cache file system.
* @param string $path The cached file path.
*
* @return \Cake\Network\Response The response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $cache->readStream($path);
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$response = new Response();
$response->type($contentType);
$response->header('Content-Length', $contentLength);
$response->body(function () use($stream) {
rewind($stream);
fpassthru($stream);
fclose($stream);
});
return $response;
}
示例2: __invoke
/**
* @return ResourceDOInterface SuspectResource if it have been deleted or OriginResource if the Suspect is not equal
*/
public function __invoke()
{
$originName = $this->originResourceDO->getName();
$suspectName = $this->suspectResourceDO->getName();
$originType = $this->originResourceDO->getType();
$suspectType = $this->suspectResourceDO->getType();
$originFilePath = $this->originResourceDO->getFilePath();
$suspectFilePath = $this->suspectResourceDO->getFilePath();
if (!$originName || !$originType) {
throw new CommandErrorException('Cannot destroy equal resource: the origin resource is empty');
}
if (!$suspectName || !$suspectType) {
throw new CommandErrorException('Cannot destroy equal resource: the suspect resource is empty');
}
if ($originFilePath === $suspectFilePath) {
throw new CommandErrorException('Cannot destroy equal resource: Origin and Suspect have same paths');
}
// Unfortunately, this condition can not always work fine.
// Because some Middlewares can compress, resize etc. the resource that saved before
// and the second uploaded copy will never be equal
if ($originType === $suspectType && $this->filesystem->has($originFilePath) === $this->filesystem->has($suspectFilePath) && $this->filesystem->getSize($originFilePath) === $this->filesystem->getSize($suspectFilePath) && $this->getFileHash($originFilePath) === $this->getFileHash($suspectFilePath)) {
$command = new DestroyResourceCommand($this->suspectResourceDO, $this->filesystem);
return $command(true);
}
return $this->originResourceDO;
}
示例3: assertBackups
/**
* Return string error message if not found to be correct
*
* @return string|bool
*/
public function assertBackups($today)
{
$day = $today;
$sizes = [];
for ($i = 0; $i < 2; $i++) {
$expected = 's77_mail_' . $day->format('Y-m-d') . '.tar.gz';
try {
$size = $this->filesystem->getSize($expected);
if ($size === false) {
return "Kan bestandsgrootte niet ophalen van '{$expected}'";
}
$sizes[] = $size;
if ($size < 3.4 * 1000 * 1000 * 1000) {
$humanSize = $size / 1000 / 1000;
return "Email backup lijkt te klein ({$humanSize} MB)";
}
} catch (\League\Flysystem\FileNotFoundException $e) {
return "Kon email backup niet vinden: '{$expected}'";
}
$day = $day->sub(new \DateInterval('P1D'));
}
if (count(array_unique($sizes)) === 1) {
return "Laatste twee e-mail backups zijn even groot.";
}
return true;
}
示例4: testLastBackupsIdentical
public function testLastBackupsIdentical()
{
$meta = $this->getMeta(123123123123.0);
$this->fs->getSize('s77_mail_2015-04-22.tar.gz')->willReturn($meta);
$this->fs->getSize('s77_mail_2015-04-21.tar.gz')->willReturn($meta);
$result = $this->assert->assertBackups(new \DateTime('2015-04-22'));
$this->assertEquals("Laatste twee e-mail backups zijn even groot.", $result);
}
示例5: setHeaders
/**
* Set the streamed response headers.
* @param StreamedResponse $response The response object.
* @return StreamedResponse
*/
public function setHeaders(StreamedResponse $response)
{
$response->headers->set('Content-Type', $this->cache->getMimetype($this->path));
$response->headers->set('Content-Length', $this->cache->getSize($this->path));
$response->setPublic();
$response->setMaxAge(31536000);
$response->setExpires(date_create()->modify('+1 years'));
$response->setLastModified(date_create()->setTimestamp($this->cache->getTimestamp($this->path)));
$response->isNotModified($this->request);
return $response;
}
示例6: _stat
/**
* Return stat for given path.
* Stat contains following fields:
* - (int) size file size in b. required
* - (int) ts file modification time in unix time. required
* - (string) mime mimetype. required for folders, others - optionally
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally
*
* If file does not exists - returns empty array or false.
*
* @param string $path file path
* @return array|false
**/
protected function _stat($path)
{
$stat = array('mime' => 'directory', 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'size' => 0);
// If root, just return from above
if ($this->root == $path) {
$stat['name'] = $this->root;
return $stat;
}
// If not exists, return empty
if (!$this->fs->has($path)) {
return array();
}
$meta = $this->fs->getMetadata($path);
// Get timestamp/size
$stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
$stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
// Check if file, if so, check mimetype
if ($meta['type'] == 'file') {
$stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
$imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
$stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
$stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
}
}
if (!isset($stat['url']) && $this->fs->getUrl()) {
$stat['url'] = 1;
}
return $stat;
}
示例7: create
/**
* Create response.
* @param FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
* @return Response Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $this->streamCallback->__invoke($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$cacheControl = 'max-age=31536000, public';
$expires = date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT';
return $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
}
示例8: getGDHandle
/**
* @return resource
*/
public function getGDHandle()
{
if (!$this->is_image) {
return null;
}
$size = $this->_filesystem->getSize($this->getPath());
$handle = $this->_filesystem->readStream($this->getPath());
return imagecreatefromstring(fread($handle, $size));
}
示例9: getSize
/**
* @override
* @inheritDoc
*/
public function getSize($path)
{
try {
$size = $this->fs->getSize($path);
return $size === false ? 0 : $size;
} catch (Error $ex) {
} catch (Exception $ex) {
}
throw new ReadException("File {$path} size could not be determined.", $ex);
}
示例10: size
/**
* Returns size of a file.
*
* @param $path
* @return int
* @throws IoReadException
*/
public function size($path)
{
try {
return $this->fs->getSize($path);
} catch (Error $ex) {
throw new IoReadException("File {$path} size could not be determined.", $ex);
} catch (Exception $ex) {
throw new IoReadException("File {$path} size could not be determined.", $ex);
}
}
示例11: outputImage
/**
* Generate and output image.
* @param string $path Image path.
* @param array $params Image manipulation params.
* @throws InvalidArgumentException
*/
public function outputImage($path, array $params)
{
$path = $this->makeImage($path, $params);
header('Content-Type:' . $this->cache->getMimetype($path));
header('Content-Length:' . $this->cache->getSize($path));
header('Cache-Control:' . 'max-age=31536000, public');
header('Expires:' . date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT');
$stream = $this->cache->readStream($path);
rewind($stream);
fpassthru($stream);
fclose($stream);
}
示例12: create
/**
* Create response.
*
* @param \League\Flysystem\FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
*
* @return \Psr\Http\Message\ResponseInterface Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = new Stream($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
if ($contentType === false) {
throw new FilesystemException('Unable to determine the image content type.');
}
if ($contentLength === false) {
throw new FilesystemException('Unable to determine the image content length.');
}
return (new Response())->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength);
}
示例13: create
/**
* Create response.
* @param FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
* @return ResponseInterface Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $this->streamCallback->__invoke($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$cacheControl = 'max-age=31536000, public';
$expires = date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT';
if ($contentType === false) {
throw new FilesystemException('Unable to determine the image content type.');
}
if ($contentLength === false) {
throw new FilesystemException('Unable to determine the image content length.');
}
return $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
}
示例14: _stat
/**
* Return stat for given path.
* Stat contains following fields:
* - (int) size file size in b. required
* - (int) ts file modification time in unix time. required
* - (string) mime mimetype. required for folders, others - optionally
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally
*
* If file does not exists - returns empty array or false.
*
* @param string $path file path
* @return array|false
**/
protected function _stat($path)
{
$stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory');
// If root, just return from above
if ($this->root == $path) {
$stat['name'] = $this->root;
return $stat;
}
// If not exists, return empty
if (!$this->fs->has($path)) {
// Check if the parent doesn't have this path
if ($this->_dirExists($path)) {
return $stat;
}
// Neither a file or directory exist, return empty
return array();
}
$meta = $this->fs->getMetadata($path);
// getMetadata() on failure
if (!$meta) {
return array();
}
// Set item filename.extension to `name` if exists
if (isset($meta['filename']) && isset($meta['extension'])) {
$stat['name'] = $meta['filename'];
if ($meta['extension'] !== '') {
$stat['name'] .= '.' . $meta['extension'];
}
}
// Get timestamp/size
$stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
$stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
// Check if file, if so, check mimetype
if ($meta['type'] == 'file') {
$stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
$imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
$stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
$stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
}
}
if (!isset($stat['url']) && $this->fs->getUrl()) {
$stat['url'] = 1;
}
return $stat;
}
示例15: size
/**
* Get the file size of a given file.
*
* @param string $path
* @return int
*/
public function size($path)
{
return $this->driver->getSize($path);
}