file handling
|remote last modified
| see demonstration of remote last modifiedfunctions to retrieve the last modified date from files on remote servers.
very practical to check if a new version of a file is ready to download on another server.
full source of remote last modified [ line 1 - 43 ] | download remote last modified
| 1 | <?php |
| 2 | function get_raw_header($host,$doc) |
| 3 | { |
| 4 | $httpheader = ''; |
| 5 | $fp = fsockopen ($host, 80, $errno, $errstr, 30); |
| 6 | if (!$fp) |
| 7 | { |
| 8 | echo $errstr.' ('.$errno.')'; |
| 9 | }else{ |
| 10 | fputs($fp, 'GET '.$doc.' HTTP/1.0'."rn".'Host: '.$host."rnrn"); |
| 11 | while(!feof($fp)) |
| 12 | { |
| 13 | $httpresult = fgets ($fp,1024); |
| 14 | $httpheader = $httpheader.$httpresult; |
| 15 | if (ereg("^rn",$httpresult)) |
| 16 | break; |
| 17 | } |
| 18 | fclose ($fp); |
| 19 | } |
| 20 | return $httpheader; |
| 21 | } |
| 22 | function get_header_array($url) |
| 23 | { |
| 24 | $url = ereg_replace('http://','',$url); |
| 25 | $endHostPos = strpos($url,'/'); |
| 26 | if(!$endHostPos) $endHostPos = strlen($url); |
| 27 | $host = substr($url,0,$endHostPos); |
| 28 | $doc = substr($url,$endHostPos,strlen($url)-$endHostPos); |
| 29 | if($doc == '') $doc = '/'; |
| 30 | $raw = get_raw_header($host,$doc); |
| 31 | $tmpArray = explode("n",$raw); |
| 32 | for ($i=0;$i<sizeof($tmpArray); $i++) |
| 33 | { |
| 34 | @list($name, $value) = explode(':', $tmpArray[$i], 2); |
| 35 | $array[trim($name)]=trim($value); |
| 36 | } |
| 37 | return $array; |
| 38 | } |
| 39 | // use like |
| 40 | $remote_file = 'http://fundisom.com/MakeNewFolderNamed.dmg'; // should be a static file like a .zip archive for example |
| 41 | $array = get_header_array($remote_file); |
| 42 | echo $remote_file.' was last modified on '.date('j F Y',strtotime($array['Last-Modified'])); |
| 43 | ?> |
36 hits by 13 users in the last 30 minutes.