note 47556 deleted from function.filesize by aidan
| From: | aidan@php.net | Date: | Wed, 13 Jul 2005 03:14:59 +0000 |
| Subject: | note 47556 deleted from function.filesize by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-91848@lists.php.net to get a copy of this message | ||
Note Submitter: Daijoubu
----
It should be URL and not URI ;)
Here's my function for retrieving remote filesize without for peoples without CURL (no auth/302
Found support)
Return the int filesize or false on failure
<?php
function filesize_remote($url, $timeout=2)
{
$url = parse_url($url);
if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] :
80), $errno, $errstr, $timeout))
{
fwrite($fp, 'HEAD '.$url['path'].$url['query']."
HTTP/1.0\r\nHost: ".$url['host']."\r\n\r\n");
stream_set_timeout($fp, $timeout);
while (!feof($fp))
{
$size = fgets($fp, 4096);
if (stristr($size, 'Content-Length') !== false) // PHP5: stripos
{
$size = trim(substr($size, 16));
break;
}
}
fclose ($fp);
}
return is_numeric($size) ? intval($size) : false;
}
?>