| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 14 | public function getFileSize($path) |
||
| 15 | { |
||
| 16 | $fp = fopen($path, "rb"); |
||
| 17 | if (!$fp) { |
||
| 18 | throw new Exception("Cannot read from file."); |
||
| 19 | } |
||
| 20 | |||
| 21 | flock($fp, LOCK_SH); |
||
| 22 | rewind($fp); |
||
| 23 | $fileSize = BigInteger::zero(); |
||
| 24 | $chunkSize = 1024 * 1024; |
||
| 25 | while (!feof($fp)) { |
||
| 26 | $readBytes = strlen(fread($fp, $chunkSize)); |
||
| 27 | $fileSize = $fileSize->plus($readBytes); |
||
| 28 | } |
||
| 29 | flock($fp, LOCK_UN); |
||
| 30 | fclose($fp); |
||
| 31 | return $fileSize; |
||
| 32 | } |
||
| 33 | } |