note 97437 added to function.filesize

From: Date: Mon, 19 Apr 2010 22:58:23 +0000
Subject: note 97437 added to function.filesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-168431@lists.php.net to get a copy of this message
Get a real filesize value, return as a string, this way it will not have the same effect as filesize() returning an integer that will be limited by 32-bit php systems. Return can be cast to a (float) to work perfectly for files over 2GB <?php // WINDOWS SERVERS: // str ntfs_filesize( str $filename ); /* DESCRIPTION: returns the filesize of a large file in string format to... ... prevent 32-bit integer walls using windows command line. */ function ntfs_filesize($filename) { return exec(" for %v in (\"".$filename."\") do @echo %~zv "); } // LINUX SERVERS: // str perl_filesize( str $filename ); /* DESCRIPTION: returns the filesize of a large file in string format to... ... prevent 32-bit integer walls using perl through linux command line. */ function perl_filesize($filename) { return exec(" perl -e 'printf \"%d\n\",(stat(shift))[7];' ".$filename." "); } // WARNING: For files over 2GB casting integers may give false values, to prevent this cast to a (float): $file = "C:/my6GBmovie.avi"; // proper filesize: 6442450944 bytes var_dump(ntfs_filesize($file); // output: string(10) "6442450944" var_dump((int)ntfs_filesize($file)); // output: int(2147483647) var_dump((float)ntfs_filesize($file)); // output: float(6442450944) ?> ---- Server IP: 208.69.120.55 Probable Submitter: 24.21.2.111 ---- Manual Page -- http://www.php.net/manual/en/function.filesize.php Edit -- https://master.php.net/note/edit/97437 Del: integrated -- https://master.php.net/note/delete/97437/integrated Del: useless -- https://master.php.net/note/delete/97437/useless Del: bad code -- https://master.php.net/note/delete/97437/bad+code Del: spam -- https://master.php.net/note/delete/97437/spam Del: non-english -- https://master.php.net/note/delete/97437/non-english Del: in docs -- https://master.php.net/note/delete/97437/in+docs Del: other reasons-- https://master.php.net/note/delete/97437 Reject -- https://master.php.net/note/reject/97437 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168431) next »