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


PHP SplFileInfo::getSize方法代码示例

本文整理汇总了PHP中SplFileInfo::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getSize方法的具体用法?PHP SplFileInfo::getSize怎么用?PHP SplFileInfo::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplFileInfo的用法示例。


在下文中一共展示了SplFileInfo::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createTransferAction

 protected function createTransferAction(\SplFileInfo $file)
 {
     // Open the file for reading
     $filename = $file->getPathName();
     if (!($resource = fopen($filename, 'r'))) {
         // @codeCoverageIgnoreStart
         throw new RuntimeException("Could not open {$filename} for reading");
         // @codeCoverageIgnoreEnd
     }
     $key = $this->options['source_converter']->convert($filename);
     $body = EntityBody::factory($resource);
     // Determine how the ACL should be applied
     if ($acl = $this->options['acl']) {
         $aclType = is_string($this->options['acl']) ? 'ACL' : 'ACP';
     } else {
         $acl = 'private';
         $aclType = 'ACL';
     }
     // Use a multi-part upload if the file is larger than the cutoff size and is a regular file
     if ($body->getWrapper() == 'plainfile' && $file->getSize() >= $this->options['multipart_upload_size']) {
         $builder = UploadBuilder::newInstance()->setBucket($this->options['bucket'])->setKey($key)->setMinPartSize($this->options['multipart_upload_size'])->setOption($aclType, $acl)->setClient($this->options['client'])->setSource($body)->setConcurrency($this->options['concurrency']);
         $this->dispatch(self::BEFORE_MULTIPART_BUILD, array('builder' => $builder, 'file' => $file));
         return $builder->build();
     }
     return $this->options['client']->getCommand('PutObject', array('Bucket' => $this->options['bucket'], 'Key' => $key, 'Body' => $body, $aclType => $acl));
 }
开发者ID:mahassan,项目名称:shellneverknow,代码行数:26,代码来源:UploadSync.php

示例2: isEmpty

 /**
  * Test is files or directories passed as arguments are empty.
  * Only valid for regular files and directories.
  *
  * @param mixed $files String or array of strings of path to files and directories.
  *
  * @return boolean True if all arguments are empty. (Size 0 for files and no children for directories).
  */
 public function isEmpty($files)
 {
     if (!$files instanceof \Traversable) {
         $files = new \ArrayObject(is_array($files) ? $files : array($files));
     }
     foreach ($files as $file) {
         if (!$this->exists($file)) {
             throw new FileNotFoundException(null, 0, null, $file);
         }
         if (is_file($file)) {
             $file_info = new \SplFileInfo($file);
             if ($file_info->getSize() !== 0) {
                 return false;
             }
         } elseif (is_dir($file)) {
             $finder = new Finder();
             $finder->in($file);
             $it = $finder->getIterator();
             $it->rewind();
             if ($it->valid()) {
                 return false;
             }
         } else {
             throw new IOException(sprintf('File "%s" is not a directory or a regular file.', $file), 0, null, $file);
         }
     }
     return true;
 }
开发者ID:inetprocess,项目名称:libsugarcrm,代码行数:36,代码来源:Filesystem.php

示例3: accept

    /**
     * UnsortedEpisodesFilter::accept()
     *
     * @return
     */
    public function accept()
    {
        $file = new SplFileInfo( $this->getInnerIterator()->current() );

        if ( !$file->isFile() )
        {
            echo "Not a file<br />";
            return false;
        }


        if ( !preg_match( '/\.(mkv|avi)$/ ', $file->getBasename() ) )
        {
            echo "Not a video<br />";
            return false;
        }

        if ( $file->getSize() < ( 25 * 1024 * 1024 ) )
        {
            echo "Too small<br />";
            return false;
        }

        $subtitleFileNames = array( $file->getBasename() . '.srt', $file->getBasename() . '.ass' );
        foreach ( $subtitleFileNames as $subtitleFileName )
            if ( file_exists( $subtitleFileName ) )
                return false;
    }
开发者ID:rangulicon,项目名称:mkvmanager,代码行数:33,代码来源:unsorted_episodes.php

示例4: boot

 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function (\Eloquent $model) {
         // If a new download file is uploaded, could be create or edit...
         $dirty = $model->getDirty();
         if (array_key_exists('filename', $dirty)) {
             $file = new \SplFileInfo($model->getAbsolutePath());
             $model->filesize = $file->getSize();
             $model->extension = strtoupper($file->getExtension());
             // Now if editing only...
             if ($model->exists) {
                 $oldFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('filename');
                 $newFilename = $dirty['filename'];
                 // Delete the old file if the filename is different to the new one, and it therefore hasn't been replaced
                 if ($oldFilename != $newFilename) {
                     $model->deleteFile($oldFilename);
                 }
             }
         }
         // If a download is edited and the image is changed...
         if (array_key_exists('image', $dirty) && $model->exists) {
             $oldImageFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('image');
             $model->deleteImageFiles($oldImageFilename);
         }
     });
     static::deleted(function ($model) {
         $model->deleteFile();
         $model->deleteImageFiles();
     });
 }
开发者ID:fbf,项目名称:laravel-downloads,代码行数:36,代码来源:Download.php

示例5: info

 public function info()
 {
     if (!isset($this->info)) {
         $this->info = new StorageInfo(array('name' => $this->file->getFilename(), 'hash' => $this->isReadable() ? $this->getHash() : null, 'format' => $this->getFormat(), 'size' => $this->isReadable() ? $this->file->getSize() : 0, 'count' => $this->isReadable() ? count($this->reader()) : 0));
     }
     return $this->info;
 }
开发者ID:mathielen,项目名称:import-engine,代码行数:7,代码来源:LocalFileStorage.php

示例6: __construct

 /**
  * @param \SplFileInfo $fileInfo
  * @param string       $downloadDirUrl
  */
 public function __construct(\SplFileInfo $fileInfo, $downloadDirUrl)
 {
     $this->size = $fileInfo->getSize();
     $this->fileName = $fileInfo->getBasename();
     $this->lastModified = \DateTime::createFromFormat("U", $fileInfo->getMTime());
     $this->url = "{$downloadDirUrl}/" . rawurlencode($this->fileName);
 }
开发者ID:becklyn,项目名称:gluggi,代码行数:11,代码来源:Download.php

示例7: __construct

    public function __construct(SplFileInfo $fileinfo = null)
    {
        parent::__construct();
        if ($fileinfo) {
            $this->file_hash = md5($fileinfo->getRealPath());
            $fileSize = $fileinfo->getSize();
            // Looking for existing path
            $result = Db::getInstance()->getRow('
				SELECT *
				FROM `' . _DB_PREFIX_ . bqSQL(self::$definition['table']) . '`
				WHERE `file_hash` = \'' . pSQL($this->file_hash) . '\'');
            if (!$result) {
                $this->file_size = $fileSize;
                $this->file_info = $fileinfo;
            } else {
                $this->id = $result['id'];
                foreach ($result as $key => $value) {
                    if (array_key_exists($key, $this)) {
                        $this->{$key} = $value;
                    }
                }
                // Check file size
                if ($this->file_size != $fileSize) {
                    $this->file_size = $fileSize;
                    $this->file_info = $fileinfo;
                }
            }
        }
        return $this;
    }
开发者ID:Benichou34,项目名称:tinify,代码行数:30,代码来源:filecache.php

示例8: calculate

 /**
  * Returns file checksum
  *
  * @param string $file
  * @return string
  */
 public function calculate($file)
 {
     $file = new \SplFileInfo($file);
     if (!$file->isFile() && !$file->isReadable()) {
         throw new \InvalidArgumentException('Invalid argument supplied for checksum calculation, only existing files are allowed');
     }
     return sprintf('%s:%s', $file->getMTime(), $file->getSize());
 }
开发者ID:ecomdev,项目名称:compiler,代码行数:14,代码来源:Basic.php

示例9: fileUploadFromFile

 /**
  * @param string $filename
  * @return FileUpload
  */
 public static function fileUploadFromFile($filename)
 {
     if (!file_exists($filename)) {
         throw new FileNotExistsException("File '{$filename}' does not exists");
     }
     $file = new \SplFileInfo($filename);
     return new FileUpload(['name' => $file->getBasename(), 'type' => $file->getType(), 'size' => $file->getSize(), 'tmp_name' => $filename, 'error' => 0]);
 }
开发者ID:ondrs,项目名称:upload-manager,代码行数:12,代码来源:Utils.php

示例10: __construct

 /**
  * Hash constructor.
  * creates a new hash set from a list of files
  *
  * @constructor
  * @access public
  * @param array $fileList
  */
 public function __construct(array $fileList)
 {
     $this->fileList = $fileList;
     foreach ($this->fileList as $filePath) {
         $file = new \SplFileInfo($filePath);
         // hash the file path, size and CTime using murmur
         $this->hashSet[$file->getRealPath()] = murmurhash3($file->getRealPath() . $file->getSize() . $file->getCTime());
     }
 }
开发者ID:Radiergummi,项目名称:anacronism,代码行数:17,代码来源:Hash.php

示例11: __construct

 public function __construct(SplFileInfo $fileInfo)
 {
     $this->perms = $fileInfo->getPerms();
     $this->size = $fileInfo->getSize();
     $this->is_dir = $fileInfo->isDir();
     $this->is_file = $fileInfo->isFile();
     $this->is_link = $fileInfo->isLink();
     if (($this->perms & 0xc000) === 0xc000) {
         $this->typename = 'File socket';
         $this->typeflag = 's';
     } elseif ($this->is_file) {
         if ($this->is_link) {
             $this->typename = 'File symlink';
             $this->typeflag = 'l';
         } else {
             $this->typename = 'File';
             $this->typeflag = '-';
         }
     } elseif (($this->perms & 0x6000) === 0x6000) {
         $this->typename = 'Block special file';
         $this->typeflag = 'b';
     } elseif ($this->is_dir) {
         if ($this->is_link) {
             $this->typename = 'Directory symlink';
             $this->typeflag = 'l';
         } else {
             $this->typename = 'Directory';
             $this->typeflag = 'd';
         }
     } elseif (($this->perms & 0x2000) === 0x2000) {
         $this->typename = 'Character special file';
         $this->typeflag = 'c';
     } elseif (($this->perms & 0x1000) === 0x1000) {
         $this->typename = 'FIFO pipe file';
         $this->typeflag = 'p';
     }
     parent::__construct('FsPath');
     $this->path = $fileInfo->getPathname();
     $this->realpath = realpath($this->path);
     if ($this->is_link && method_exists($fileInfo, 'getLinktarget')) {
         $this->linktarget = $fileInfo->getLinktarget();
     }
     $flags = array($this->typeflag);
     // User
     $flags[] = $this->perms & 0x100 ? 'r' : '-';
     $flags[] = $this->perms & 0x80 ? 'w' : '-';
     $flags[] = $this->perms & 0x40 ? $this->perms & 0x800 ? 's' : 'x' : ($this->perms & 0x800 ? 'S' : '-');
     // Group
     $flags[] = $this->perms & 0x20 ? 'r' : '-';
     $flags[] = $this->perms & 0x10 ? 'w' : '-';
     $flags[] = $this->perms & 0x8 ? $this->perms & 0x400 ? 's' : 'x' : ($this->perms & 0x400 ? 'S' : '-');
     // Other
     $flags[] = $this->perms & 0x4 ? 'r' : '-';
     $flags[] = $this->perms & 0x2 ? 'w' : '-';
     $flags[] = $this->perms & 0x1 ? $this->perms & 0x200 ? 't' : 'x' : ($this->perms & 0x200 ? 'T' : '-');
     $this->contents = implode($flags);
 }
开发者ID:jnvsor,项目名称:kint,代码行数:57,代码来源:FsPath.php

示例12: _parse

 /**
  * @param mixed $variable
  *
  * @return false|null
  */
 protected function _parse(&$variable)
 {
     /** @noinspection PhpUsageOfSilenceOperatorInspection */
     if (is_object($variable) || is_array($variable) || (string) $variable !== $variable || strlen($variable) > 2048 || preg_match('[[:?<>"*|]]', $variable) || !@is_readable($variable)) {
         return false;
     }
     try {
         $fileInfo = new \SplFileInfo($variable);
         $flags = array();
         $perms = $fileInfo->getPerms();
         if (($perms & 0xc000) === 0xc000) {
             $type = 'File socket';
             $flags[] = 's';
         } elseif (($perms & 0xa000) === 0xa000) {
             $type = 'File symlink';
             $flags[] = 'l';
         } elseif (($perms & 0x8000) === 0x8000) {
             $type = 'File';
             $flags[] = '-';
         } elseif (($perms & 0x6000) === 0x6000) {
             $type = 'Block special file';
             $flags[] = 'b';
         } elseif (($perms & 0x4000) === 0x4000) {
             $type = 'Directory';
             $flags[] = 'd';
         } elseif (($perms & 0x2000) === 0x2000) {
             $type = 'Character special file';
             $flags[] = 'c';
         } elseif (($perms & 0x1000) === 0x1000) {
             $type = 'FIFO pipe file';
             $flags[] = 'p';
         } else {
             $type = 'Unknown file';
             $flags[] = 'u';
         }
         // owner
         $flags[] = $perms & 0x100 ? 'r' : '-';
         $flags[] = $perms & 0x80 ? 'w' : '-';
         $flags[] = $perms & 0x40 ? $perms & 0x800 ? 's' : 'x' : ($perms & 0x800 ? 'S' : '-');
         // group
         $flags[] = $perms & 0x20 ? 'r' : '-';
         $flags[] = $perms & 0x10 ? 'w' : '-';
         $flags[] = $perms & 0x8 ? $perms & 0x400 ? 's' : 'x' : ($perms & 0x400 ? 'S' : '-');
         // world
         $flags[] = $perms & 0x4 ? 'r' : '-';
         $flags[] = $perms & 0x2 ? 'w' : '-';
         $flags[] = $perms & 0x1 ? $perms & 0x200 ? 't' : 'x' : ($perms & 0x200 ? 'T' : '-');
         $this->type = $type;
         $this->size = sprintf('%.2fK', $fileInfo->getSize() / 1024);
         $this->value = implode($flags);
     } catch (\Exception $e) {
         return false;
     }
 }
开发者ID:voku,项目名称:kint,代码行数:59,代码来源:Kint_Parsers_FsPath.php

示例13: get_size

/**
 * Get the size of a directory or a file
 *
 * @param SplFileInfo $file SplFileInfo instance
 *
 * @return int The calculated size
 */
function get_size(\SplFileInfo $file)
{
    $size = 0;
    try {
        if ($file->isFile()) {
            $size += $file->getSize();
        } else {
            foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($file->getRealpath())) as $f) {
                $size += $f->getSize();
            }
        }
    } catch (\RuntimeException $e) {
    }
    return $size;
}
开发者ID:Arkhana,项目名称:Cakebox,代码行数:22,代码来源:utils.php

示例14: read

 /**
  * Reads a file
  *
  * @param string $key
  * @param bool $includeContent
  *
  * @return File|boolean
  */
 public function read($key, $includeContent = true)
 {
     if (!$this->exists($key) || !is_readable($key)) {
         return false;
     }
     $info = new \SplFileInfo($key);
     $file = new File();
     $file->size = $info->getSize();
     $file->name = $info->getFilename();
     if ($includeContent) {
         $file->content = file_get_contents($info->getRealPath());
     }
     $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
     $file->mime = finfo_file($fileInfo, $info->getRealPath());
     finfo_close($fileInfo);
     return $file;
 }
开发者ID:piflex,项目名称:FilesystemBundle,代码行数:25,代码来源:Filesystem.php

示例15: build_dir_hashmap

 /**
  * Builds hashmap for given directory.
  *
  * @param string $directory  Directory for hashmap creation.
  * @param array  $exclusions List of excluded file names.
  *
  * @return array Hashmap.
  */
 public function build_dir_hashmap($directory, $exclusions = array())
 {
     $directory_iterator = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
     $recursive_iterator = new RecursiveIteratorIterator($directory_iterator);
     $files = new RegexIterator($recursive_iterator, '/^.+\\.(less|css|php)$/i', RegexIterator::GET_MATCH);
     $hashmap = array();
     foreach ($files as $file) {
         $file_info = new SplFileInfo($file[0]);
         $file_path = $file_info->getPathname();
         if (in_array($file_info->getFilename(), $exclusions)) {
             continue;
         }
         $key = str_replace(array($directory, '/'), array('', '\\'), $file_path);
         $hashmap[$key] = array('size' => $file_info->getSize(), 'sha1' => sha1_file($file_path));
     }
     ksort($hashmap);
     return $hashmap;
 }
开发者ID:sedici,项目名称:wpmu-istec,代码行数:26,代码来源:misc.php


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