note 97437 deleted from function.filesize by aharvey
| From: | aharvey@php.net | Date: | Tue, 22 Jan 2013 00:21:01 +0000 |
| Subject: | note 97437 deleted from function.filesize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193333@lists.php.net to get a copy of this message | ||
Note Submitter: jbudpro at comcast dot net
----
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)
?>