<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.readfile">
 <refnamediv>
  <refname>readfile</refname>
  <refpurpose>Outputs a file</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type class="union"><type>int</type><type>false</type></type><methodname>readfile</methodname>
   <methodparam><type>string</type><parameter>filename</parameter></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>use_include_path</parameter><initializer>&false;</initializer></methodparam>
   <methodparam choice="opt"><type>resource</type><parameter>context</parameter></methodparam>
  </methodsynopsis>
  <para>
   Reads a file and writes it to the output buffer.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>filename</parameter></term>
     <listitem>
      <para>
       The filename being read.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>use_include_path</parameter></term>
     <listitem>
      <para>
       You can use the optional second parameter and set it to &true;, if
       you want to search for the file in the <link
       linkend="ini.include-path">include_path</link>, too.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>context</parameter></term>
     <listitem>
      <para>
       A context stream <type>resource</type>.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns the number of bytes read from the file on success,
   &return.falseforfailure;
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  &fs.emits.warning.on.failure;
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>Forcing a download using <function>readfile</function></title>
    <programlisting role="php">
<![CDATA[
<?php
$file = 'monkey.gif';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <mediaobject>
     <alt>Open / Save dialogue</alt>
     <imageobject>
      <imagedata fileref="en/reference/filesystem/figures/readfile.png"/>
     </imageobject>
    </mediaobject>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;

  <note>
   <para>
    <function>readfile</function> will not present any memory issues, 
    even when sending large files, on its own. If you encounter an 
    out of memory error ensure that output buffering is off with 
    <function>ob_get_level</function>.
   </para>
  </note>

  &tip.fopen-wrapper;
  &note.context-support;
 </refsect1>
 
 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>fpassthru</function></member>
    <member><function>file</function></member>
    <member><function>fopen</function></member>
    <member><function>include</function></member>
    <member><function>require</function></member>
    <member><function>virtual</function></member>
    <member><function>file_get_contents</function></member>
    <member><xref linkend="wrappers"/></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
-->