|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-11-27 06:16 UTC] roman dot hlynovskiy at gmail dot com
Description: ------------ filesize returns negative values for big files Test script: --------------- $f = '/home/bigfile.data'; $s = filesize($f); print "$s\n"; Expected result: ---------------- 2336962885 Actual result: -------------- -1958004411 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 17:00:01 2025 UTC |
hmm, feature is something missing in a product, however this one is a plain bug. perl, python, 3-line c program, stat, ls they all return correct size. what is wrong with php to return correct filesize? this is strace cut: --- stat64("/home/data/bigfile.data", {st_mode=S_IFREG|0644, st_size=2336962885, ...}) = 0 write(1, "-1958004411\n", 12-1958004411 --- it's clear that from system level correct size is returned. it's a matter of using correct types to store and return the value from php perspectivePHP's internal integer type is a signed `long`. with 32bit 2336962885 is out of range. While properly printing it gives you the correct value: php -r 'printf("%u", -1958004411);' 2336962885 Besides that there are projects for large file support (while that's not as relevant on most 64bit systems [except windows 64bit] these days where it works out of the box) and for aritrary size "integer" types. But both projects aren't trivial due to the wayand amount of 3rd party libraries PHP interacts with. If you have a constructive proposal/solution for those we're more than happy to implement those, though.