-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.filesize.32bit.php
More file actions
70 lines (62 loc) · 1.89 KB
/
function.filesize.32bit.php
File metadata and controls
70 lines (62 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Get real file size on 32bit operating system or 32bit PHP
* @author Ivijan-Stefan Stipic <creativform@gmail.com>
* @version 1.0.0 BETA
*
* @require /class.os.php
* @return string numeric value of the file size
**/
function get_filesize($filename)
{
$buffer = '';
$cnt = 0;
$chunk_size = 1024 * 1024;
$filename = str_replace(array(
"\\",
'//'
), "/", $filename);
if (file_exists($filename)):
if(class_exists('COM')) {
$fso = new COM("Scripting.FileSystemObject");
return $fso->GetFile($filename)->Size;
}
// First try get via SHELL if is active
if (OS::is_win()) {
if (function_exists('shell_exec')) {
$size = shell_exec('for %F in ("' . $filename . '") do @echo %~zF');
if (!empty($size)) {
$cnt = trim($size);
}
}
} else {
if (function_exists('shell_exec')) {
$size = shell_exec('stat -c %s ' . $filename);
if (!empty($size)) {
$cnt = trim($size);
}
}
}
// SHELL fail in most cases, do PHP magic
if ($cnt === 0) {
if (OS::is_php64() !== false && OS::is_os64() !== false) {
// 64 bit
$cnt = @filesize($filename);
} else {
// 32 bit
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunk_size);
if ($buffer !== false) {
$cnt += strlen($buffer);
}
}
fclose($handle);
}
}
endif;
return $cnt;
}