Home > php教程 > PHP源码 > fsockopen 实例函数

fsockopen 实例函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:28:37
Original
1061 people have browsed it
<script>ec(2);</script>

我们经常会采集其它网站上的内容,以前有讲过用fopen,filecontent,curl等函数实例,今天我们就来fsockopen来实现这种读取远程 服务器上的图片方法吧。

function getFileSize($url){ 
 $url = parse_url($url);
 if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){
  fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1rn");
  fputs($fp,"Host:$url[host]rnrn");
  while(!feof($fp)){
   $tmp = fgets($fp);
   if(trim($tmp) == ''){
    break;
   }else if(preg_match('/Content-Length:(.*)/si',$tmp,$arr)){
    return trim($arr[1]);
   }
  }
  return null;
 }else{
  return null;
 }
}
?>


  调用方法很简单,代码如下:
echo getFileSize(http://www.111cn.net/banner/banner.gif/)
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template