note 43993 added to function.fstat
| From: | spam at jodyleblanc dot com | Date: | Mon, 12 Jul 2004 02:29:36 +0000 |
| Subject: | note 43993 added to function.fstat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73072@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.fstat.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43993
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43993&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43993&report=yes
Search -- http://master.php.net/manage/user-notes.php