$url = https://r3---sn-5jucgv5qc5oq-cagl.googlevideo.com/videoplayback?initcwndbps=2133750&mime=video%2Fmp4&ipbits=0&fexp=900720%2C907263%2C909721%2C930824%2C934954%2C9405651%2C9405972%2C9406849%2C9407103%2C9407756%2C9407880%2C9408102%2C942310%2C943610%2C948124%2C948703%2C951511%2C951703%2C952302%2C952612%2C952901%2C955301%2C957201%2C957507%2C958600%2C959701%2C961404%2C962727&ratebypass=yes&itag=18&requiressl=yes&sver=3&mm=31&id=o-AH3LjJikaNXn9Fxj1nCeZeGQxBRB2Env2Cd-Rwumwn2U&mt=1426837685&mv=m&ms=au&ip=106.51.132.147&dur=336.596&pl=24&upn=NV9m09pWiSg&source=youtube&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&expire=1426859426&key=yt5&signature=42A2FFA9C6EAFF6EBACC605EE5E06FA7B38805DB.9F608D789F6516F43E25A77B841B428975ADC7A4
如何获取此网址引用的文件的大小。当我打开此网址时,视频文件启动流式传输。但我需要文件大小才能强制下载使用header('content-length')
字段将文件下载到浏览器
答案 0 :(得分:3)
您可以使用cURL执行此操作:
我可以看到您正在使用https
网址,因此它会帮助您
<?php
$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, 'http://upload.wikimedia.org/wikipedia/commons/a/af/Bonsai_IMG_6426.jpg');
curl_setopt($ch, CURLOPT_URL, 'https://r3---sn-5jucgv5qc5oq-cagl.googlevideo.com/videoplayback?initcwndbps=2133750&mime=video%2Fmp4&ipbits=0&fexp=900720%2C907263%2C909721%2C930824%2C934954%2C9405651%2C9405972%2C9406849%2C9407103%2C9407756%2C9407880%2C9408102%2C942310%2C943610%2C948124%2C948703%2C951511%2C951703%2C952302%2C952612%2C952901%2C955301%2C957201%2C957507%2C958600%2C959701%2C961404%2C962727&ratebypass=yes&itag=18&requiressl=yes&sver=3&mm=31&id=o-AH3LjJikaNXn9Fxj1nCeZeGQxBRB2Env2Cd-Rwumwn2U&mt=1426837685&mv=m&ms=au&ip=106.51.132.147&dur=336.596&pl=24&upn=NV9m09pWiSg&source=youtube&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&expire=1426859426&key=yt5&signature=42A2FFA9C6EAFF6EBACC605EE5E06FA7B38805DB.9F608D789F6516F43E25A77B841B428975ADC7A4');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
var_dump($size);
?>
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://weknowyourdreams.com/images/love/love-01.jpg');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
var_dump($size);
?>
答案 1 :(得分:1)
尝试curl以curl_getinfo()
$ch = curl_init('http://www.example.com/yourfile'); //put your url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
echo $size;
答案 2 :(得分:0)
尝试使用filesize():
<?php
$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';
?>