php获取远程文件大小

来源:百度知道 编辑:UC知道 时间:2024/05/22 00:04:25
下面这段php代码是计算远程文件的函数,文件在几MB时能正确运行,到几十MB时就溢出(显示为0MB)了,高手帮忙解决下。
没有PHP专区,只好贴到这来了,不要给我其它语言的代码,只要PHP的。
function remote_filesize($uri,$user='',$pw='')
{
// start output buffering
ob_start();
// initialize curl with given uri
$ch = curl_init($uri);
// make sure we get the header
curl_setopt($ch, CURLOPT_HEADER, 1);
// make it a http HEAD request
curl_setopt($ch, CURLOPT_NOBODY, 1);
// if auth is needed, do it here
if (!empty($user) && !empty($pw))
{
$headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$okay = curl_exec($ch);
curl_close($ch);
// get the output buffer
$head = ob_get_contents();
// clean the output buffer and return to previous
// buffer settings
ob_end_clean();

// gets you the numeric value from the Content-Length
// fi

你的代码没有问题!

<?php
#### 此代码由 工具啦(http://www.Tool.La) 转换 ####

echo"function remote_filesize($uri,$user='',$pw='') "
. "{ "
. "// start output buffering "
. "ob_start(); "
. "// initialize curl with given uri "
. "$ch = curl_init($uri); "
. "// make sure we get the header "
. "curl_setopt($ch, CURLOPT_HEADER, 1); "
. "// make it a http HEAD request "
. "curl_setopt($ch, CURLOPT_NOBODY, 1); "
. "// if auth is needed, do it here "
. "if (!empty($user) && !empty($pw)) "
. "{ "
. "$headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw)); "
. "curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); "
. &quo