<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'Get Remote Filesize'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Tue, 14 Feb 2012 03:49:57 GMT</pubDate>
<item>
<title>neirauni said on 6/28/11</title>
<link>http://snipplr.com/view/29/get-remote-filesize/</link>
<description><![CDATA[ function remotefilesize($url) { 
  
  $ch = curl_init($url); 
  curl_setopt($ch, CURLOPT_HEADER, 1); 
  curl_setopt($ch, CURLOPT_NOBODY, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_exec($ch);
  
  // get some variables
  $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 200
  $filesize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); //filesize
  $fimemime = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); //mimetype, ex: image/jpeg
  
  curl_close($ch);
  
  if( 200 != $status )
    throw new Exception('Arquivo não encontrado!');

  return $filesize;
}

printf('PHP logo has %s bytes', remotefilesize("http://br2.php.net/images/php.gif") ); ]]></description>
<pubDate>Tue, 28 Jun 2011 03:36:14 GMT</pubDate>
<guid>http://snipplr.com/view/29/get-remote-filesize/</guid>
</item>
<item>
<title>neirauni said on 6/28/11</title>
<link>http://snipplr.com/view/29/get-remote-filesize/</link>
<description><![CDATA[ <code>

</code> ]]></description>
<pubDate>Tue, 28 Jun 2011 03:35:31 GMT</pubDate>
<guid>http://snipplr.com/view/29/get-remote-filesize/</guid>
</item>
<item>
<title>neirauni said on 6/28/11</title>
<link>http://snipplr.com/view/29/get-remote-filesize/</link>
<description><![CDATA[ Hi, I found this code very useful also.

I got the arharp's version and changed  a little bit, here my version:




Regards. ]]></description>
<pubDate>Tue, 28 Jun 2011 03:34:14 GMT</pubDate>
<guid>http://snipplr.com/view/29/get-remote-filesize/</guid>
</item>
<item>
<title>arharp said on 4/19/10</title>
<link>http://snipplr.com/view/29/get-remote-filesize/</link>
<description><![CDATA[ You can do this without using an output buffer by setting CURLOPT_RETURNTRANSFER to 1

Like so:

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_RETURNTRANSFER, 1);

  if (!empty($user) &amp;&amp; !empty($pw)) {
    $headers = array('Authorization: Basic ' .  base64_encode("$user:$pw"));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  }

  $head = curl_exec($ch);
  curl_close($ch);

  $regex = '/Content-Length:\s([0-9].+?)\s/';
  $count = preg_match($regex, $head, $matches);

  return isset($matches[1]) ? $matches[1] : false;
} ]]></description>
<pubDate>Mon, 19 Apr 2010 16:45:00 GMT</pubDate>
<guid>http://snipplr.com/view/29/get-remote-filesize/</guid>
</item>
<item>
<title>adulau said on 12/28/06</title>
<link>http://snipplr.com/view/29/get-remote-filesize/</link>
<description><![CDATA[ <p>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.</p>

<p>There is lengthy discussion about remote filesize on : http://be.php.net/function.filesize </p>
 ]]></description>
<pubDate>Thu, 28 Dec 2006 02:42:57 GMT</pubDate>
<guid>http://snipplr.com/view/29/get-remote-filesize/</guid>
</item>
</channel>
</rss>
