<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Incero &#187; size</title>
	<atom:link href="http://www.incero.com/tag/size/feed" rel="self" type="application/rss+xml" />
	<link>http://www.incero.com</link>
	<description>Technology done right</description>
	<lastBuildDate>Sun, 29 Aug 2010 07:52:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Checking Remote File Size With PHP</title>
		<link>http://www.incero.com/webdev/checking-remote-file-size-with-php</link>
		<comments>http://www.incero.com/webdev/checking-remote-file-size-with-php#comments</comments>
		<pubDate>Thu, 15 Oct 2009 18:13:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[size]]></category>

		<guid isPermaLink="false">http://www.incero.com/?p=239</guid>
		<description><![CDATA[If you&#8217;re going to grab a file from a remote server using PHP it may be useful to know how large the file is before grabbing it. We can check the remote file headers for the file size by using CURL like so: function remote_filesize($url, $user = &#8220;&#8221;, $pw = &#8220;&#8221;) { ob_start(); $ch = [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re going to grab a file from a remote server using PHP it may be useful to know how large the file is before grabbing it. We can check the remote file headers for the file size by using CURL like so:</p>
<blockquote><p>function remote_filesize($url, $user = &#8220;&#8221;, $pw = &#8220;&#8221;) {<br />
ob_start();<br />
$ch = curl_init($url);<br />
curl_setopt($ch, CURLOPT_HEADER, 1);<br />
curl_setopt($ch, CURLOPT_NOBODY, 1);</p>
<p>if(!empty($user) &amp;&amp; !empty($pw))<br />
{<br />
$headers = array(&#8216;Authorization: Basic &#8216; . base64_encode(&#8220;$user:$pw&#8221;));<br />
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);<br />
}</p>
<p>$ok = curl_exec($ch);<br />
curl_close($ch);<br />
$head = ob_get_contents();<br />
ob_end_clean();</p>
<p>$regex = &#8216;/Content-Length:s([0-9].+?)s/&#8217;;<br />
$count = preg_match($regex, $head, $matches);</p>
<p>return isset($matches[1]) ? $matches[1] : &#8220;unknown&#8221;;<br />
}</p></blockquote>
<p>To use the function we could do something like this:</p>
<blockquote><p>$file=&#8221;http://img1.putpic.com/images/main/10/28719152288-orig.jpg&#8221;;<br />
echo remote_filesize($file);</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.incero.com/webdev/checking-remote-file-size-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
