您的位置:首页 > 其它

快速获取远程文件的大小

2015-05-29 00:00 369 查看
摘要: 获取http/ftp文件长度

<?php

// 快速获取远程文件大小
// http 文件
$url = 'http://bbs.csdn.net/topics/360076220';
// ftp 文件
// $username = 'xxxx';//ftp帐号
// $password = 'xxxx';//ftp密码
// $url = 'xxx.xxx.xxx/xx.xxx'; //ftp服务器地址+文件路径+文件名例如: ftp.t35.com/down.zip
// $ftp_server = "ftp://" . $username . ":" . $password . "@" . $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_URL, $ftp_server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
$output = curl_exec($ch);
curl_close($ch);
preg_match('#Content-Length: (\d+)#i', $output, $arr);
if (isset($arr[1])) {
echo '远程文件大小: ', $arr[1], PHP_EOL;
} else {
echo 'error', PHP_EOL;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息