日期:2011-09-04  浏览次数:20497 次

 

在昨天做端口测试的基础上研究一下PHP上传与下载的代码,结果想起前段时间笔试题有一道题是在上传文件时显示文件内容,让我对PHP实现读取远程文件的功能很感兴趣,以下是代码:

01 function urlfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE  , $ip = '', $timeout = 15, $block = TRUE, $encodetype  = 'URLENCODE') {
02           $return = '';
03           $matches = parse_url($url);
04           $host = $matches['host'];
05           $path = $matches['path'] ? $matches['path'].(isset($matches['query']) ? '?'.$matches['query'] : '') : '/';
06           $port = !empty($matches['port']) ? $matches['port'] : 80;
07  
08           if($post) {
09             $out = "POST $path HTTP/1.0\r\n";