使該功能:
<?php
getResourceSize($remoteFile /*link of the file*/)
{
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here)
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
echo 'cURL failed';
exit;
}
$contentLength = 'unknown';
$status = 'unknown';
if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
$status = (int)$matches[1];
if($status == ('404' || '500') return 'error';
}
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$contentLength = (int)$matches[1];
return $contentLength;
}
}
?>
現在初始化總下載量爲:
$files = array
[
"http://...firstFile.ext",
"http://...secondFile.ext",
"http://...thirdFile.ext",
...
];
$totalDownloadSize = 0;
foreach($file in $files)
$totalDownloadSize += GetResourceSize($file);