首页 > 其他 > 详细

快速获取远程文件的大小

时间:2015-05-29 12:21:36      阅读:308      评论:0      收藏:0      [点我收藏+]
<?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;
}



快速获取远程文件的大小

原文:http://my.oschina.net/meowmeow/blog/422127

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!