Comments (2)
I'm using the built-in PHP function filesize
. Here is a note on that page:
Note: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.
http://php.net/manual/en/function.filesize.php
from file-directory-list.
In user notes section of this manual page there are few resolution for this issue.
Please consider using something like:
<?php
/**
* Return file size (even for file > 2 Gb)
* For file size over PHP_INT_MAX (2 147 483 647), PHP filesize function loops from -PHP_INT_MAX to PHP_INT_MAX.
*
* @param string $path Path of the file
* @return mixed File size or false if error
*/
function realFileSize($path)
{
if (!file_exists($path))
return false;
$size = filesize($path);
if (!($file = fopen($path, 'rb')))
return false;
if ($size >= 0)
{//Check if it really is a small file (< 2 GB)
if (fseek($file, 0, SEEK_END) === 0)
{//It really is a small file
fclose($file);
return $size;
}
}
//Quickly jump the first 2 GB with fseek. After that fseek is not working on 32 bit php (it uses int internally)
$size = PHP_INT_MAX - 1;
if (fseek($file, PHP_INT_MAX - 1) !== 0)
{
fclose($file);
return false;
}
$length = 1024 * 1024;
while (!feof($file))
{//Read the file until end
$read = fread($file, $length);
$size = bcadd($size, $length);
}
$size = bcsub($size, $length);
$size = bcadd($size, strlen($read));
fclose($file);
return $size;
}
from file-directory-list.
Related Issues (20)
- Cant see files or folders with utf8 characters HOT 3
- Please make it responsive HOT 1
- Password Protect? HOT 2
- Filetime and filesize warnings HOT 5
- Linking to the parent folder?
- Ingnore directory HOT 2
- Start Path HOT 2
- changing $path to a user sub-directory isnt working HOT 4
- correct path on modal version
- Adding Icons HOT 1
- 2 feature HOT 1
- Folders look like files HOT 1
- Problem with folders names containing dots
- How can i make .html files open in new tab HOT 1
- Not working with ssl HOT 1
- Password Protection HOT 1
- m4v and m4a to items list.
- Download count
- No working at all after control panel update (plesk)
- to remove HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from file-directory-list.