note 105204 added to function.filesize

From: Date: Tue, 02 Aug 2011 21:57:18 +0000
Subject: note 105204 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-182121@lists.php.net to get a copy of this message
this is modified from arne's code below, which doesn't calculate the filesize correctly... This should be the correct one: function fsize($file) { // filesize will only return the lower 32 bits of // the file's size! Make it unsigned. $fmod = filesize($file); var_dump($fmod); if ($fmod < 0) $fmod += 2.0 * (PHP_INT_MAX + 1); var_dump($fmod); // find the upper 32 bits $i = 0; $myfile = fopen($file, "r"); // feof has undefined behaviour for big files. // after we hit the eof with fseek, // fread may not be able to detect the eof, // but it also can't read bytes, so use it as an // indicator. while (strlen(fread($myfile, 1)) === 1) { fseek($myfile, PHP_INT_MAX, SEEK_CUR); fseek($myfile, 1, SEEK_CUR); fseek($myfile, PHP_INT_MAX, SEEK_CUR); $i++; } fclose($myfile); --$i; // add the lower 32 bit to our 2 * PHP_INT_MAX multiplier return ($i * 2.0 * (PHP_INT_MAX + 1)) + $fmod; } ---- Server IP: 69.147.83.197 Probable Submitter: 147.21.160.5 ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- https://master.php.net/note/edit/105204 Del: integrated -- https://master.php.net/note/delete/105204/integrated Del: useless -- https://master.php.net/note/delete/105204/useless Del: bad code -- https://master.php.net/note/delete/105204/bad+code Del: spam -- https://master.php.net/note/delete/105204/spam Del: non-english -- https://master.php.net/note/delete/105204/non-english Del: in docs -- https://master.php.net/note/delete/105204/in+docs Del: other reasons-- https://master.php.net/note/delete/105204 Reject -- https://master.php.net/note/reject/105204 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182121) next »