PHP: SplFileInfo::getSize - Manual
(PHP 5 >= 5.1.2, PHP 7, PHP 8)
SplFileInfo::getSize — Gets file size
Parameters
This function has no parameters.
Return Values
The filesize in bytes on success, or false on failure.
Errors/Exceptions
A RuntimeException will be thrown if the file does not exist or an error occurs.
Examples
Example #1 SplFileInfo::getSize() example
<?php
$info = new SplFileInfo('example.jpg');
echo $info->getFilename() . " " . $info->getSize();
?>The above example will output something similar to:
Found A Problem?
random-citizen at example dot org ¶
8 years ago
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 :|3 years ago
When getSize return 0, after fwrtite, You must use clearstatcache:
$tmpFile = new \SplFileObject('/tmp/file.txt');
$fp = $tmpFile->openFile('w');
$fp->fwrite('123');
$fp->fflush();
echo $fp->getSize(); //Return 0
clearstatcache();
echo $fp->getSize(); //Return 3
https://bugs.php.net/bug.php?id=72182franssen dot roland at gmail dot com ¶
15 years ago
Seems to return FALSE if file does not exists... (PHP 5.3.4)