<?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;
}
}
?>
|