當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。