تشخیص حجم فایل یک لینک
مثلا حجم یک فایل زیپ یک لینک دانلود رو که از سایت دیگه است رو مشخص میکنه

کد PHP:

<?php
  $remoteFile 
'http://download.thinkbroadband.com/5MB.zip';
$ch curl_init($remoteFile);
curl_setopt($chCURLOPT_NOBODYtrue);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_HEADERtrue);
curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
$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 (
preg_match('/Content-Length: (\d+)/'$data$matches)) {
  
$contentLength = (float)$matches[1];
  }
   
  
//echo 'HTTP Status: ' . $status . "\n";
//echo 'Content-Length: ' . $contentLength;
 
 
 
 
function format_bytes($contentLength) {
    
$units = array(' B'' KB'' MB'' GB'' TB');
    for (
$i 0$contentLength >= 1024 && $i 4$i++) $contentLength /= 1024;
    return 
round($contentLength2).$units[$i];
}
 
echo 
format_bytes($contentLength);
 
 
?>