在 x86平台 , 檔案容量最大只有2^(32-1),相當於2G,超過以後,用一般方式會無法取得正確的容量
為了節省運算的時間,所以,會採用CURL,來進行資料的運算
function sizeCurl($files) {
// curl solution - cross platform and really cool 🙂
if (function_exists("curl_init")) {
$ch = curl_init("file://" . $files);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
curl_close($ch);
if ($data !== false && preg_match('/Content-Length: (\d+)/', $data, $matches)) {
return (string) $matches[1];
}
} else {
return false;
}
}
以 CURL 取得檔案的Header,透過 Content-Length 來取得檔案的大小,這樣就完成了32bit環境下取得超過運算位元的檔案大小。