Login   Register  
PHP Classes
elePHPant
Icontem

File: class.RemoteFileStats.inc

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Daniel Kushner  >  RemoteFileStats  >  class.RemoteFileStats.inc  >  Download  
File: class.RemoteFileStats.inc
Role: ???
Content type: text/plain
Description: Retrieves file statistics of a remote file
Class: RemoteFileStats
Retrieves statistics of a remote file (http)
Author: By
Last change:
Date: 2002-05-12 16:05
Size: 1,709 bytes
 

Contents

Class file image Download
<?php

class RemoteFileStats {

	var $error;
	var $errno;
	var $errstr;
		
	var $remoteSever;
	var $remoteLastModified;
	var $remoteFileSize;
	var $remoteFileType;
	
	var $httpTranslate = array('Server' => 'remoteSever',
					   		   'Last-Modified' => 'remoteLastModified',
					   		   'Content-Length' => 'remoteFileSize',
					   		   'Content-Type' => 'remoteFileType'
					   		   ); 
	var $stats = array('remoteSever' => '',
					   'remoteLastModified' => '',
					   'remoteFileSize' => '',
					   'remoteFileType' => ''
					   );
	
	function RemoteFileStats($host, $file, $port = 80) {
		$file = preg_replace("#^\/|^#i", "/", $file);
		$this->error = false;
		
		$fp = fsockopen ($host, $port, $this->errno, $this->errstr, 30);
		if($fp) {
			fputs ($fp, "HEAD $file HTTP/1.0\r\n");
			fputs ($fp, "Host: $host\r\n" );
			fputs ($fp, "\r\n");
			
			while(!feof($fp)) {
				$line = fgets($fp,4096);
				if(preg_match("/^([a-zA-Z\-]+): ([[:ascii:]]+)$/", $line, $arr)) {
					if(isset($this->httpTranslate[$arr[1]])) {
						$this->stats[$this->httpTranslate[$arr[1]]] = $arr[2];
					}
				}
			}
		} else {
			$this->error = true;
		}
	}
	
	function getRemoteServer() {
		return $this->stats['remoteSever'];
	}

	function getRemoteLastModified() {
		return $this->stats['remoteLastModified'];
	}
	
	function getRemoteFileSize() {
		return $this->stats['remoteFileSize'];
	}
	
	function getRemoteFileType() {
		return $this->stats['remoteFileType'];		
	}
	
	function inError() {
		return $this->error;
	}
	
	function getErrorStr() {
		return $this->errstr;
	}
	
	function getErrorNo() {
		return $this->errno;
	}
	
}
?>