Php 使用curl限制文件大小
我使用以下代码在下载前控制文件大小:Php 使用curl限制文件大小,php,curl,Php,Curl,我使用以下代码在下载前控制文件大小: $info = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); // make it a HEAD request curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url);
$info = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true); // make it a HEAD request
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_USERAGENT,$this->userAgent());
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,$webinfo['ctimeout']);
curl_setopt($ch, CURLOPT_TIMEOUT, $webinfo['timeout']); //timeout in seconds
$head = curl_exec($ch);
$info['type'] = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$info['size'] = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
$info['path'] = parse_url($url, PHP_URL_PATH);
$info['filename'] = substr($info['path'], strrpos($info['path'], '/') + 1);
$info['http'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$info['url'] = $url;
$info['active'] = false;
if(curl_errno($ch))
{
echo curl_error($ch);
curl_close($ch);
return false;
}
if($info['http'] == 200)
{
$info['active'] = true;
curl_close($ch);
if( $info['size'] > 15728640)
{
return false;
}
return $info;
}
所以我把它限制在15mb左右,但我今天检查了我的服务器,发现它下载了一个超过200mb的文件
我的代码有什么错
我想也许“15728640”是错的,或者我应该用另一种格式写它吗 可能有用或重复:可能有用或重复:可能有用或重复: