php 异步获取文件下载文件大小(不用下载)

function getContentLength($strURL)
{
$resURL = curl_init();
curl_setopt($resURL, CURLOPT_URL, $strURL);
curl_setopt($resURL, CURLOPT_PROGRESSFUNCTION, 'progressCallback');
curl_setopt($resURL, CURLOPT_NOPROGRESS, false);
curl_setopt($resURL, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec ($resURL);
curl_close ($resURL);

}

function progressCallback($resource, $download_size = 0, $downloaded = 0, $upload_size = 0, $uploaded = 0)
{
global $lens;
if ($download_size > 0) {
$res = curl_getinfo($resource);
$url = $res['url'];
$pkg = strstr($url,'?id=');
$pkg = str_replace('?id=','',$pkg);
$lens[$pkg] = $download_size;
return $res;
}

}
posted @ 2018-04-10 13:44  screte  阅读(377)  评论(0编辑  收藏  举报