SplFileInfo::getSize
(PHP 5 >= 5.1.2, PHP 7, PHP 8)
SplFileInfo::getSize — ファイルサイズを取得する
パラメータ
この関数にはパラメータはありません。
戻り値
ファイルサイズをバイト数で返します。
失敗時に false
を返します。
エラー / 例外
ファイルが存在しなかった場合やエラーが発生した場合に RuntimeException をスローします。
例
例1 SplFileInfo::getSize() の例
<?php
$info = new SplFileInfo('example.jpg');
echo $fileinfo->getFilename() . " " . $fileinfo->getSize();
?>
上の例の出力は、 たとえば以下のようになります。
example.jpg 15385
+add a note
User Contributed Notes 4 notes
random-citizen at example dot org ¶
6 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 :|
Anonymous ¶
8 years ago
Check http://php.net/manual/en/function.filesize.php#115792 for fast and reliable version of filesize for files >2gb on 32 bit systems.
Pawel B. ¶
1 year 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=72182
franssen dot roland at gmail dot com ¶
13 years ago
Seems to return FALSE if file does not exists... (PHP 5.3.4)
↑ and ↓ to navigate •
Enter to select •
Esc to close
Press Enter without
selection to search using Google