note 68882 added to function.filesize
| From: | g8z at yahoo dot com | Date: | Mon, 14 Aug 2006 19:48:30 +0000 |
| Subject: | note 68882 added to function.filesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115902@lists.php.net to get a copy of this message | ||
<?php
/**
Here is a CURL version of the remote_filesize function,
which also supports http authentication if required.
Courtesy of the $5 Script Archive: http://www.tufat.com
**/
// EXAMPLE:
echo remote_filesize("http://download.tufat.com/test.zip","","");
function remote_filesize($url, $user = "", $pw = "") {
ob_start();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
if(!empty($user) && !empty($pw)) {
$headers = array('Authorization: Basic ' . base64_encode("$user:$pw"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$ok = curl_exec($ch);
curl_close($ch);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
return isset($matches[1]) ? $matches[1] : "unknown";
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 24.182.33.247
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.filesize.php
Edit -- https://master.php.net/note/edit/68882
Del: integrated -- https://master.php.net/note/delete/68882/integrated
Del: useless -- https://master.php.net/note/delete/68882/useless
Del: bad code -- https://master.php.net/note/delete/68882/bad+code
Del: spam -- https://master.php.net/note/delete/68882/spam
Del: non-english -- https://master.php.net/note/delete/68882/non-english
Del: in docs -- https://master.php.net/note/delete/68882/in+docs
Del: other reasons-- https://master.php.net/note/delete/68882
Reject -- https://master.php.net/note/reject/68882
Search -- https://master.php.net/manage/user-notes.php