Published in: PHP
Retrieves the filesize of a remote file. I can't take the credit for this function. I grabbed it somewhere online a few years back. Don't remember where.
function remote_filesize($url, $user = "", $pw = "") { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $ok = curl_exec($ch); curl_close($ch); $regex = '/Content-Length:\s([0-9].+?)\s/'; }
Comments
Subscribe to comments
You need to login to post a comment.

Quite useful. In that example, you'll need curl compiled with PHP. Sometimes curl is not available, the same behavior could be achieved using a simple socket (fsockopen) connection in PHP. Using a HEAD request (fputs the corresponding request Headers) and get the value from the headers itself (matching Content-Length:) (as described in line 19. of the curl example). PHP 5 is including nifty function for HTTP connection handling and parsing the headers.
There is lengthy discussion about remote filesize on : http://be.php.net/function.filesize