SplFileInfo::getSize

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

SplFileInfo::getSizeGets file size

说明

public SplFileInfo::getSize ( ) : int

Returns the filesize in bytes for the file referenced.

参数

此函数没有参数。

返回值

The filesize in bytes.

错误/异常

A RuntimeException will be thrown if the file does not exist or an error occurs.

参见

User Contributed Notes

random-citizen at example dot org 30-May-2018 08:38
If you're using Symfony's UploadedFile, 
please be aware that if you call this method 
_after_ you call @move, you will most likely get 
some obscenely untraceable error, that says:

`stat failed`

Which if you really think about it, it does makes sense, 
the file has been moved by Symfony, but getSize is in SplFileInfo, 
and SplFileInfo doesn't know that the file has been moved.

Weirdly enough, that error doesn't come on my work mac :|
contact at socialdevelop dot biz 01-Apr-2016 05:59
if use it as SplFileInfo::getSize - it return false if file not found
if use it as SplFileObject::getSize - it generate RuntimeException: SplFileObject::__construct(my-file): failed to open stream: No such file or directory
franssen dot roland at gmail dot com 30-Apr-2011 05:59
Seems to return FALSE if file does not exists... (PHP 5.3.4)