Web Development Knowledge Base
| |
Sections :
You too, please publish your useful code snippets in any programming language : write an article ! Plateforme d'envoi de gros fichiers en ligne Dépannage site web Blog infogérance Hébergement e-mail |
Olivier Ligny - - 19/08/2012 - vue 41789 fois
Get file size in PHP for files larger than 2 GBYou may encounter some problems when using the filesize() function of PHP on large files (> 2 GB). Here is a workaround to get file size with no limit.
function filesize2($path) {
if(@is_dir($path)) {
return 0;
}
$sizeInBytes = @filesize($path);
if($sizeInBytes===false) {
$command = "/bin/ls -l ".escapeshellarg($path);
$ret = trim(exec($command));
if(!substr_count($ret, "ls:") && !substr_count($ret, "Aucun fichier")) {
$ret = str_replace("\t", " ", $ret);
$ret = str_replace(" ", " ", $ret);
$ret = str_replace(" ", " ", $ret);
$ret = str_replace(" ", " ", $ret);
$arr = explode(" ", $ret);
$sizeInBytes = $arr[4];
}
}
return $sizeInBytes;
}
Jan Kuchar - 05/02/2016
You can also use Big File Tools - https://github.com/jkuchar/BigFileTools. Library for manipulating files over 2GB in PHP. More details in my original answer on stackoverflow: http://stackoverflow.com/a/35233556/631369
|
| Nos partenaires : iPhone 8 Cases & Protection | |