<?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>C file input/output &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/c-file-inputoutput/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Use fopen() to Check File Availability?</title>
		<link>/2011/04/07/use-fopen-to-check-file-availability/</link>
		<comments>/2011/04/07/use-fopen-to-check-file-availability/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 12:46:33 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[C file input/output]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[HEAD]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=2268</guid>
		<description><![CDATA[Zend Framework and Zend_Http_Client I&#8217;ve posted about Zend_Http_Client. Simply there you can &#8216;make&#8217; your own http client and you can request a remote file. Just to check what&#8217;s going on with this file. // new HTTP request to a file $httpClient = new Zend_Http_Client('http://www.example.com/myfile.mp4'); // get the HEAD of the response and match agains the &#8230; <a href="/2011/04/07/use-fopen-to-check-file-availability/" class="more-link">Continue reading <span class="screen-reader-text">Use fopen() to Check File Availability?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<li><a href="/2011/04/13/post-with-zend_http_client/" rel="bookmark" title="POST with Zend_Http_Client">POST with Zend_Http_Client </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Zend Framework and Zend_Http_Client</h2>
<figure id="attachment_2287" style="width: 450px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/04/file.jpg"><img class="size-full wp-image-2287" title="PHP's fopen() can be used to check remote file existence" src="/wp-content/uploads/2011/04/file.jpg" alt="PHP's fopen() can be used to check remote file existence" width="450" height="415" srcset="/wp-content/uploads/2011/04/file.jpg 450w, /wp-content/uploads/2011/04/file-300x276.jpg 300w" sizes="(max-width: 450px) 100vw, 450px" /></a><figcaption class="wp-caption-text">PHP&#39;s fopen() can be used to check remote file existence</figcaption></figure>
<p>I&#8217;ve posted about <a title="Zend Http Client Class Docs" href="http://framework.zend.com/manual/en/zend.http.client.advanced.html" target="_blank">Zend_Http_Client</a>. Simply there you can &#8216;make&#8217; your own http client and you can request a remote file. Just to check what&#8217;s going on with this file.</p>
<pre lang="php" escaped="true">// new HTTP request to a file
$httpClient = new Zend_Http_Client('http://www.example.com/myfile.mp4');

// get the HEAD of the response and match agains the
// Content-Length. That's because using the Content-Type is slower
$response = $httpClient-&gt;request(Zend_Http_Client::HEAD);

// if the Content-Length is 0 the file doesn't exists
if (0 === (int)$response-&gt;getHeader('Content-Length')) {
	echo 'the file doesn\'t exits';
}
</pre>
<p>However is there any other way to answer the same question?</p>
<h2>fopen()</h2>
<p>Yes and no? Perhaps yes, but you should be careful. I&#8217;m still not sure it can be used in any case. However here&#8217;s the snippet.</p>
<pre lang="php" escaped="true">if (FALSE === @fopen('http://www.example.com/myfile.mp4', 'r')) {
	echo 'the file doesn\'t exists';
}
</pre>
<p><a title="fopen() PHP Manpage" href="http://php.net/manual/en/function.fopen.php" target="_blank">fopen()</a> will return FALSE whenever the file doesn&#8217;t exists.</p>
<p>In both cases I request a remote file &#8211; an MPEG-4 file. Note that fopen()&#8217;s first parameter can be a HTTP resource.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<li><a href="/2011/04/13/post-with-zend_http_client/" rel="bookmark" title="POST with Zend_Http_Client">POST with Zend_Http_Client </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/04/07/use-fopen-to-check-file-availability/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://www.example.com/myfile.mp4" length="0" type="video/mp4" />
		</item>
	</channel>
</rss>
