note 43993 deleted from function.fstat by tomsommer

From: Date: Mon, 12 Jul 2004 07:22:52 +0000
Subject: note 43993 deleted from function.fstat by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73081@lists.php.net to get a copy of this message
Note Submitter: spam@jodyleblanc.com ---- Since fstat() won't work on REMOTE FILES, you have to dig up filesize info, etc elsewhere. Here's what did the trick for me to get filesize and a few other headers: function http_get_info($url) { $url_stuff = parse_url($url); $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80; $fp = fsockopen($url_stuff['host'], $port); $query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n"; $query .= 'Host: ' . $url_stuff['host']; $query .= "\n\n"; fwrite($fp, $query); while ($tmp = fread($fp, 1024)) { $buffer .= $tmp; if (strstr($tmp, "Content-Type")) break; } preg_match('/Date: ([^\n]*)/', $buffer, $parts); $info["Date"] = $parts[1]; preg_match('/Server: ([^\n]*)/', $buffer, $parts); $info["Server"] = $parts[1]; preg_match('/Last-Modified: ([^\n]*)/', $buffer, $parts); $info["Last-Modified"] = $parts[1]; preg_match('/ETag: ([^\n]*)/', $buffer, $parts); $info["ETag"] = $parts[1]; preg_match('/Accept-Ranges: ([^\n]*)/', $buffer, $parts); $info["Accept-Ranges"] = $parts[1]; preg_match('/Content-Length: ([^\n]*)/', $buffer, $parts); $info["Content-Length"] = $parts[1]; preg_match('/Content-Type: ([^\n]*)/', $buffer, $parts); $info["Content-Type"] = $parts[1]; return $info; }

« previous php.notes (#73081) next »