php-doc-en/reference/filesystem/functions/fpassthru.xml
Mehdi Achour e8844eadb3 some more CS
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@146748 c90b9560-bf6c-de11-be94-00142212c4b1
2003-12-18 17:46:56 +00:00

104 lines
3.3 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
<refentry id="function.fpassthru">
<refnamediv>
<refname>fpassthru</refname>
<refpurpose>Output all remaining data on a file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>fpassthru</methodname>
<methodparam><type>resource</type><parameter>handle</parameter></methodparam>
</methodsynopsis>
<simpara>
Reads to EOF on the given file pointer from the current position and
writes the results to the output buffer.
</simpara>
<simpara>
If an error occurs, <function>fpassthru</function> returns
&false;. Otherwise, <function>fpassthru</function> returns
the number of characters read from <parameter>handle</parameter>
and passed through to the output.
</simpara>
<simpara>
The file pointer must be valid, and must point to a file successfully
opened by <function>fopen</function>, <function>popen</function>, or
<function>fsockopen</function>. You may need to call
<function>rewind</function> to reset the file pointer to the beginning of
the file if you have already written data to the file. The file is
closed when <function>fpassthru</function> is done reading it (leaving
<parameter>handle</parameter> useless).
</simpara>
<simpara>
If you just want to dump the contents of a file to the output buffer,
without first modifying it or seeking to a particular offset, you may
want to use the <function>readfile</function>, which saves you
the <function>fopen</function> call.
</simpara>
<note>
<para>
When using <function>fpassthru</function> on a binary file on Windows
systems, you should make sure to open the file in binary mode by
appending a <literal>b</literal> to the mode used in the call to
<function>fopen</function>.
</para>
<para>
You are encouraged to use the <literal>b</literal> flag when dealing
with binary files, even if your system does not require it, so that
your scripts will be more portable.
</para>
</note>
<para>
<example>
<title>Using <function>fpassthru</function> with binary files</title>
<programlisting role="php">
<![CDATA[
<?php
// open the file in a binary mode
$name = ".\public\dev\img\ok.png";
$fp = fopen($name, 'rb');
// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// dump the picture and stop the script
fpassthru($fp);
exit;
?>
]]>
</programlisting>
</example>
</para>
<simpara>
See also <function>readfile</function>,
<function>fopen</function>, <function>popen</function>, and
<function>fsockopen</function>
</simpara>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->