本文整理汇总了PHP中Symfony\Component\Finder\SplFileInfo::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getSize方法的具体用法?PHP SplFileInfo::getSize怎么用?PHP SplFileInfo::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getSize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSize
/**
* @param bool $human
* @return int|string
*/
public function getSize($human = true)
{
$humanFilesize = function ($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
};
$size = $this->fileInfo->getSize();
if ($human) {
$size = $humanFilesize($size);
}
return $size;
}
示例2: __construct
/**
* Create sprite image data holder
* @param string $path
* @param SplFileInfo $fileInfo
*/
public function __construct($path, SplFileInfo $fileInfo)
{
$this->basePath = $path;
$this->info = $fileInfo;
// Assign fileinfo variables
$this->path = $this->info->getPathname();
$this->size = $this->info->getSize();
// Assign image data
$info = getimagesize($this->path);
if (!is_array($info)) {
throw new UnexpectedValueException("The image '{$this->path}' is not a correct image format.");
}
$this->hash = sha1(file_get_contents($this->getFullPath()));
$this->width = (int) $info[0];
$this->height = (int) $info[1];
$this->mime = $info['mime'];
$this->type = explode('/', $this->mime)[1];
// Assign css name
$ext = $this->info->getExtension();
// Replace path parts with `-`
$name = str_replace(['/', '\\', '_'], '-', $this->info->getRelativePathname());
// Remove leading `-`
$name = preg_replace('~^-*~', '', $name);
// Remove double dashes
$name = preg_replace('~-+~', '-', $name);
// Remove file extension
$name = preg_replace("~\\.{$ext}\$~", '', $name);
// Replace dots with -
$name = preg_replace('~\\.~', '-', $name);
$this->name = $name;
}
示例3:
function it_should_filter_by_size(SplFileInfo $file1, SplFileInfo $file2)
{
$file1->isFile()->willReturn(true);
$file2->isFile()->willReturn(true);
$file1->getRealPath()->willReturn($this->tempFile);
$file2->getRealPath()->willReturn($this->tempFile);
$file1->getSize()->willReturn(8 * 1024);
$file2->getSize()->willReturn(16 * 1024);
$result = $this->size('>= 4K')->size('<= 10K');
$result->shouldBeAnInstanceOf('GrumPHP\\Collection\\FilesCollection');
$result->count()->shouldBe(1);
$files = $result->toArray();
$files[0]->shouldBe($file1);
}
示例4: addMetadatas
/**
* addMetadatas
*
* @param \Symfony\Component\Finder\SplFileInfo $file
* @param mixed $object
* @param string $scope
*/
public function addMetadatas($file, $object, $scope)
{
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$now = new \DateTime('now');
$metadataArray = array('FILESIZE' => $this->getHumanFileSize($file->getSize()), 'AUTHOR' => $user->getLastname() . ' ' . $user->getFirstName(), 'VERSION' => 'v.' . $now->format('YmdHis'), 'DESCRIPTION' => '');
$metadatas = $this->registry->getManager()->getRepository('Erichard\\DmsBundle\\Entity\\DocumentMetadata')->findByScope(array($scope, 'both'));
foreach ($metadatas as $metadata) {
if (array_key_exists($metadata->getName(), $metadataArray)) {
$metadataLnk = $scope == 'document' ? new DocumentMetadataLnk($metadata) : new DocumentNodeMetadataLnk($metadata);
$metadataLnk->setValue($metadataArray[$metadata->getName()]);
$this->registry->getManager()->persist($metadataLnk);
$object->addMetadata($metadataLnk);
}
}
}
示例5: fileInfo
/**
* Todas las propiedades de un archivo o directorio
*
* @param SplFileInfo $file Object of SplFileInfo
* @param string $path Ruta de la carpeta o archivo
* @return array|null Lista de propiedades o null si no es leible
*/
public function fileInfo($file, $path)
{
if ($file->isReadable()) {
$item = $this->fileDetails;
$item["filename"] = $file->getFilename();
$item["filetype"] = $file->getExtension();
$item["lastmodified"] = $file->getMTime();
$item["size"] = $file->getSize();
if ($file->isDir()) {
$item["filetype"] = '';
$item["isdir"] = true;
$item["urlfolder"] = $path . $item["filename"] . '/';
$item['preview'] = '';
} elseif ($file->isFile()) {
$thumb = $this->createThumb($file, $path);
if ($thumb) {
$item['preview'] = $this->config['url'] . $this->config['source'] . '/_thumbs' . $path . $thumb;
}
$item['previewfull'] = $this->config['url'] . $this->config['source'] . $path . $item["filename"];
}
return $item;
} else {
return;
}
}
示例6: isFileEmpty
/**
* Checks if a file is empty.
*
* @param SplFileInfo $file
*
* @return bool
*/
private function isFileEmpty(SplFileInfo $file)
{
return $file->getSize() > 0 ? false : true;
}
示例7: getSize
public function getSize()
{
return $this->fileInfo->getSize();
}