2012-10-04 7 views
0

cURL은 페이지의 총 다운로드 크기를 얻을 수 있지만 전체 다운로드 이미지 크기, 다운로드 한 총 스크립트 크기, 전체 스타일 시트 크기로 다운로드 크기를 나눌 수 있습니다. 등 등 ...이 링크 PHP: Remote file size without downloading file컬 - 초기 컬 요청에서 각 파일 크기 가져 오기

내가 그것을 루프를하고 함께 할 수있는 뭔가가 생각하고와 크기를 얻을 컬을 발견

이 일에 대해가는 일반적인 방법은 무엇

inital curl 요청에 의해 끌어온 각 파일의

누군가에게 조언이 있으면 알려주세요.

감사

답변

0

이 기능을 확인하십시오 :

$files = array 
[ 
    "http://...firstFile.ext", 
    "http://...secondFile.ext", 
    "http://...thirdFile.ext", 
    ... 
]; 

$totalDownloadSize = 0; 

foreach($file in $files) 
    $totalDownloadSize += GetResourceSize($file); 
:

<?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; 
     } 
    } 
?> 

이제 귀하의 총 다운로드 크기를 초기화를