php-doc-en/reference/filesystem/functions/fpassthru.xml
Daniel Egeberg 96c9d88bad Converted to utf-8
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@297028 c90b9560-bf6c-de11-be94-00142212c4b1
2010-03-28 22:10:10 +00:00

134 lines
3.4 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.fpassthru">
<refnamediv>
<refname>fpassthru</refname>
<refpurpose>Output all remaining data on a file pointer</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>fpassthru</methodname>
<methodparam><type>resource</type><parameter>handle</parameter></methodparam>
</methodsynopsis>
<para>
Reads to EOF on the given file pointer from the current position and
writes the results to the output buffer.
</para>
<para>
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.
</para>
<para>
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.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>handle</parameter></term>
<listitem>
&fs.validfp.all;
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
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.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Using <function>fpassthru</function> with binary files</title>
<programlisting role="php">
<![CDATA[
<?php
// open the file in a binary mode
$name = './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>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<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>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>readfile</function></member>
<member><function>fopen</function></member>
<member><function>popen</function></member>
<member><function>fsockopen</function></member>
</simplelist>
</para>
</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:"~/.phpdoc/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
-->