当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFileInfo::getSize方法代码示例

本文整理汇总了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;
 }
开发者ID:swiss-php-friends,项目名称:database-dump-provider,代码行数:17,代码来源:Dump.php

示例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;
 }
开发者ID:maslosoft,项目名称:sprite,代码行数:36,代码来源:SpriteImage.php

示例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);
 }
开发者ID:kientrunghuynh,项目名称:grumphp,代码行数:14,代码来源:FilesCollectionSpec.php

示例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);
         }
     }
 }
开发者ID:DavidG04,项目名称:ErichardDmsBundle,代码行数:22,代码来源:DmsManager.php

示例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;
     }
 }
开发者ID:guillermomartinez,项目名称:filemanager-php,代码行数:32,代码来源:Filemanager.php

示例6: isFileEmpty

 /**
  * Checks if a file is empty.
  *
  * @param SplFileInfo $file
  *
  * @return bool
  */
 private function isFileEmpty(SplFileInfo $file)
 {
     return $file->getSize() > 0 ? false : true;
 }
开发者ID:andreas-weber,项目名称:php-junit-merge,代码行数:11,代码来源:Command.php

示例7: getSize

 public function getSize()
 {
     return $this->fileInfo->getSize();
 }
开发者ID:phramz,项目名称:doctrine-annotation-scanner,代码行数:4,代码来源:ClassFileInfo.php


注:本文中的Symfony\Component\Finder\SplFileInfo::getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。